You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support a self-referencing models, where a given model can be a child of itself to support infinite-depth hierarchies.
For the most part, DiffSync seems to support this,
Use Case
Note that we're currently not sure if we need this functionality. We're exploring options and our problem might be solved by a flat object hierarchy with object ordering. Never the less, I figured I'd start a discussion thread about it in case others had a need for this and/or if this is actually a bug.
Example use-cases:
Directory structures (LDAP, Active Directory)
Site/Location structures
File system
Example model with some test code.
from __future__ importannotationsimportjsonfromtypingimportList, MappingimportstructlogfromdiffsyncimportDiffSync, DiffSyncModel, Difffromdiffsync.enumimportDiffSyncStatus, DiffSyncFlagsfromstructlog.stdlibimportBoundLoggerclassTenant(DiffSyncModel):
_modelname="tenant"_identifiers= ("name",)
_shortname= ()
_attributes= ("display",)
_children= {"tenant": "children"}
children: List[Tenant] = []
name: strdisplay: strclassTestBackend(DiffSync):
tenant=Tenanttop_level= [ "tenant" ]
logger: BoundLoggerdef__init__(self, logger=None, dry_run=None):
super().__init__()
self.logger=structlog.get_logger("TestBackend")
defload1(self) ->None:
"""Load an example tree"""# Create some sample thingst1=Tenant(name="a", display="All the things")
self.add(t1)
t2=Tenant(name="a/b", display="Buzz")
t1.add_child(t2)
self.add(t2)
t3=Tenant(name="a/b/c", display="See you later")
t2.add_child(t3)
self.add(t3)
defload2(self) ->None:
"""Load an example tree, similar to load1(), except with some attribute changets"""# Create some sample thingst1=Tenant(name="a", display="Al the tings")
self.add(t1)
t2=Tenant(name="a/b", display="bzzzz")
t1.add_child(t2)
self.add(t2)
t3=Tenant(name="a/b/c", display="See you now")
t2.add_child(t3)
self.add(t3)
defdemo1():
be1=TestBackend()
be1.load1()
be2=TestBackend()
be2.load2()
# Preview diffdiff=be1.diff_to(be2)
print(diff.str())
print(diff.dict())
# NOTE: The diff shows some duplicates# Syncbe1.sync_to(be2)
# Note that `a/b` is updated 2 times# Note that `a/b/c` is updated 3 times
The text was updated successfully, but these errors were encountered:
Environment
Proposed Functionality
Support a self-referencing models, where a given model can be a child of itself to support infinite-depth hierarchies.
For the most part, DiffSync seems to support this,
Use Case
Note that we're currently not sure if we need this functionality. We're exploring options and our problem might be solved by a flat object hierarchy with object ordering. Never the less, I figured I'd start a discussion thread about it in case others had a need for this and/or if this is actually a bug.
Example use-cases:
Example model with some test code.
The text was updated successfully, but these errors were encountered: