Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gioccher opened this issue May 20, 2024 · 2 comments · May be fixed by #496
Open

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

gioccher opened this issue May 20, 2024 · 2 comments · May be fixed by #496
Assignees
Labels
integration: contrib Contrib related issues and PRs type: bug Issues/PRs addressing a bug.

Comments

@gioccher
Copy link

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

  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
Copy link
Contributor

Interesting point. There is networktocode/diffsync#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.

@jdrew82 jdrew82 added type: bug Issues/PRs addressing a bug. integration: contrib Contrib related issues and PRs labels Jul 18, 2024
@gioccher
Copy link
Author

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)

@Renrut5 Renrut5 self-assigned this Jul 31, 2024
@Renrut5 Renrut5 linked a pull request Aug 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration: contrib Contrib related issues and PRs type: bug Issues/PRs addressing a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants