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

Fix issues with items that have been committed, then removed and replaced by new items #445

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

soininen
Copy link
Collaborator

@soininen soininen commented Aug 29, 2024

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 in commit_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

  • Documentation (also in Toolbox repo) is up-to-date
  • Release notes have been updated
  • Unit tests have been added/updated accordingly
  • Code has been formatted by black & isort
  • Unit tests pass

Parameter definition id can replace entity class (id) when
adding parameter value items.
All items (except Asterisk which is a special case) have the same
item type, no need to store it per-instance.
Previously, if a new item would replace a removed item (fetched from
database, then removed), we would just mark the new item as 'to_update'.
However, if the new item was later removed,
commit would fail because the new item never didn't have a DB id.

Now, instead of 'stealing' the removed item's identity by setting
a new item's status to 'to_update', we keep the status as 'to_add'
and store the removed item for later removal on commit.
This way the new items replaces the removed on in a clean way.
@soininen soininen merged commit 905bb45 into master Aug 29, 2024
14 checks passed
@soininen soininen deleted the fix_scenario_alternative_ranks branch August 29, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant