nautobot / nautobot-app-ssot

Single Source of Truth for Nautobot
https://docs.nautobot.com/projects/ssot/en/latest/
Other
34 stars 28 forks source link

Custom relationships items ordering is not ignored when calculating changes #457

Open gioccher opened 1 month ago

gioccher commented 1 month ago

This is an issue in ssot:contrib CustomRelationshipAnnotation with custom relationships items ordering

Environment

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

  1. define a many-to-many relationship and a ssot job that syncs from external to nautobot
  2. add multiple elements to the relationship in the external system
  3. 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
  4. 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

image

image

Kircheneer commented 1 week ago

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.