Fix issues with items that have been committed, then removed and replaced by new items #445
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.
Consider a scenario where we fetch an item from the database, then remove the item. Since the item has been removed, it is possible to add a new item with the same unique key. Previously, the new item would "steal" the removed item's "identity" by settings its status to
to_update
and the removed item was deleted from the mapped table. However, since the new item did not yet have a database id, removing it caused a Traceback incommit_session()
.Stealing the removed item's id and giving it to the new item would not work because we must be able to delete the removed item's referrers in cascade: just adding a new imposer item with the same unique keys does not save the referrers.
This PR solves the issue by replacing the "identity steal" by a mechanism that stores the removed item for later removal on commit. This allows proper cascade delete of the removed item and its referrers.
No associated issue
Checklist before merging