Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 30
Implement DiffSyncModelFlags.NATURAL_DELETION_ORDER.#220
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -350,11 +350,7 @@ def sync_diff_element(self, element: DiffElement, parent_model: Optional["DiffSy | ||
| attrs = diffs.get("+", {}) | ||
| # Retrieve Source Object to get its flags | ||
| src_model: Optional["DiffSyncModel"] | ||
| try: | ||
| src_model = self.src_diffsync.get(self.model_class, ids) | ||
| except ObjectNotFound: | ||
| src_model = None | ||
| src_model = self.src_diffsync.get_or_none(self.model_class, ids) | ||
Kircheneer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # Retrieve Dest (and primary) Object | ||
| dst_model: Optional["DiffSyncModel"] | ||
| @@ -364,31 +360,43 @@ def sync_diff_element(self, element: DiffElement, parent_model: Optional["DiffSy | ||
| except ObjectNotFound: | ||
| dst_model = None | ||
| natural_deletion_order = False | ||
| skip_children = False | ||
| # Set up flag booleans | ||
| if dst_model: | ||
| natural_deletion_order = bool(dst_model.model_flags & DiffSyncModelFlags.NATURAL_DELETION_ORDER) | ||
| skip_children = bool(dst_model.model_flags & DiffSyncModelFlags.SKIP_CHILDREN_ON_DELETE) | ||
| changed = False | ||
| if natural_deletion_order and self.action == DiffSyncActions.DELETE and not skip_children: | ||
| for child in element.get_children(): | ||
| changed |= self.sync_diff_element(child, parent_model=dst_model) | ||
| changed, modified_model = self.sync_model(src_model=src_model, dst_model=dst_model, ids=ids, attrs=attrs) | ||
| dst_model = modified_model or dst_model | ||
| if not modified_model or not dst_model: | ||
| self.logger.warning("No object resulted from sync, will not process child objects.") | ||
| return changed | ||
| if self.action == DiffSyncActions.CREATE: # type: ignore | ||
| if self.action == DiffSyncActions.CREATE: | ||
| if parent_model: | ||
| parent_model.add_child(dst_model) | ||
| self.dst_diffsync.add(dst_model) | ||
| elif self.action == DiffSyncActions.DELETE: | ||
| if parent_model: | ||
| parent_model.remove_child(dst_model) | ||
| skip_children = bool(dst_model.model_flags & DiffSyncModelFlags.SKIP_CHILDREN_ON_DELETE) | ||
| self.dst_diffsync.remove(dst_model, remove_children=skip_children) | ||
| if skip_children: | ||
| return changed | ||
| self.incr_elements_processed() | ||
| for child in element.get_children(): | ||
| changed |= self.sync_diff_element(child, parent_model=dst_model) | ||
| if not natural_deletion_order: | ||
| for child in element.get_children(): | ||
| changed |= self.sync_diff_element(child, parent_model=dst_model) | ||
| return changed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -53,13 +53,14 @@ class MyAdapter(DiffSync): | ||
| ### Supported Model Flags | ||
| | Name | Description | Binary Value | | ||
| |---|---|---| | ||
| | Name | Description | Binary Value | | ||
| |---|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---| | ||
| | IGNORE | Do not render diffs containing this model; do not make any changes to this model when synchronizing. Can be used to indicate a model instance that exists but should not be changed by DiffSync. | 0b1 | | ||
| | SKIP_CHILDREN_ON_DELETE | When deleting this model, do not recursively delete its children. Can be used for the case where deletion of a model results in the automatic deletion of all its children. | 0b10 | | ||
| | SKIP_UNMATCHED_SRC | Ignore the model if it only exists in the source/"from" DiffSync when determining diffs and syncing. If this flag is set, no new model will be created in the target/"to" DiffSync. | 0b100 | | ||
| | SKIP_UNMATCHED_DST | Ignore the model if it only exists in the target/"to" DiffSync when determining diffs and syncing. If this flag is set, the model will not be deleted from the target/"to" DiffSync. | 0b1000 | | ||
| | SKIP_UNMATCHED_BOTH | Convenience value combining both SKIP_UNMATCHED_SRC and SKIP_UNMATCHED_DST into a single flag | 0b1100 | | ||
| | SKIP_CHILDREN_ON_DELETE | When deleting this model, do not recursively delete its children. Can be used for the case where deletion of a model results in the automatic deletion of all its children. | 0b10 | | ||
| | SKIP_UNMATCHED_SRC | Ignore the model if it only exists in the source/"from" DiffSync when determining diffs and syncing. If this flag is set, no new model will be created in the target/"to" DiffSync. | 0b100 | | ||
| | SKIP_UNMATCHED_DST | Ignore the model if it only exists in the target/"to" DiffSync when determining diffs and syncing. If this flag is set, the model will not be deleted from the target/"to" DiffSync. | 0b1000 | | ||
| | SKIP_UNMATCHED_BOTH | Convenience value combining both SKIP_UNMATCHED_SRC and SKIP_UNMATCHED_DST into a single flag | 0b1100 | | ||
| | NATURAL_DELETION_ORDER | When deleting, delete children before instances of this model. | 0b10000 | | ||
Kircheneer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ## Working with flags | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.