Custom relationships items ordering is not ignored when calculating changes
This is an issue in ssot:contrib CustomRelationshipAnnotation with custom relationships items ordering
Environment
- Python version: 3.9.19
- Nautobot version: 2.2.3
- nautobot-ssot version: 2.6.1
Expected Behavior
No changes are detected after running the sync a 2nd time
Observed Behavior
The same set of changes is detected running the sync multiple times. The only difference is the order of items in the custom relationship.
Steps to Reproduce
- define a many-to-many relationship and a ssot job that syncs from external to nautobot
- add multiple elements to the relationship in the external system
- run the ssot sync. This populates the custom relationship with items, but sometimes in a different order from what's defined in the external system
- run the ssot sync again. This second sync should not detect any changes, but sometimes you'll see the same list of detected changes in the Data Sync tab, and ssot attempting to apply the update again in the Sync Logs tab
Interesting point. There is https://github.com/networktocode/diffsync/issues/25 which would address this, until then, if you need a quick fix for this, I recommend you do something like
class YourAdapter(NautobotAdapter):
...
def load(...):
return_value = super.load(...)
for obj in self.get_all("modelname"):
obj.field = sorted(obj.field, key=lambda o: o.trunk_groups)
self.update(obj)
return return_value
This should sort your values to be consistent - you need to change this such that it matches your other adapter, or change the other adapter, too.
Thanks, the quick fix works
class YourAdapter(NautobotAdapter):
...
def load(self):
super().load()
for obj in self.get_all(self.interface):
obj.trunk_groups = sorted(obj.trunk_groups, key=operator.itemgetter("name"))
self.update(obj)