Skip to content

DiffSyncModel: Create/Update ordering and Delete ordering #97

Closed

Description

@FragmentedPacket

This came up in internal conversations around usage and some potential improvements.

Potentially adding a flag that will set the create/update to process parents before children and then also the reverse, children are deleted before parents.

An example would be Nautobot and the dependencies of objects within Nautobot. Say you want to delete a site, but children objects exist such as devices, you need to delete the devices before deleting the site. This caused some intermittent and hard to troubleshoot scenarios.

It was brought up that some of these deletions would be deferred as well which may not be wanted.

Activity

  1. Kircheneer commented on Mar 4, 2022

    @Kircheneer
    Contributor

    I had this scenario as well, for my use case (which might be generalizable) I have taken a approach similar to this:

    class CustomerOrderingDiff(Diff):
        def get_children(self) -> Iterator["DiffElement"]:
            deferred_children = []
    
            for child in self.children["some_model_that_other_models_depend_on"].values():
                if child.action == DiffSyncActions.DELETE:
                    deferred_children.append(child)
                else:
                    yield child
            
            for group in self.groups():
                if group == "some_model_that_other_models_depend_on":
                    continue
                order_method_name = f"order_children_{group}"
                if hasattr(self, order_method_name):
                    order_method = getattr(self, order_method_name)
                else:
                    order_method = getattr(self, order_default)
    
                yield from order_method(self.children[group])
            yield from deferred_children

    I'll look into possibly contributing this once I have the approach fleshed out a little more.

  2. self-assigned this
    on Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions