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

CAY-2853 Incorrect deletion of entities from flattened attributes #614

Conversation

Jugen
Copy link
Contributor

@Jugen Jugen commented May 7, 2024

When deleting an ObjEntity with flattened attributes Cayenne deletes the related DB attribute's row as well.

So if we have for example an ObjEntity "FlatPainting" with flattened attribute "galleryName". If we then delete a "FlatPainting" then the associated gallery will also be deleted, leaving all other paintings at that gallery without a valid Gallery link.

Furthermore if we add to our "FlatPainting" a "gallery" relationship attribute with delete rule Deny, the gallery was still being deleted.

The original intention was for something like a "PaintingFull" ObjEntity having all painting attributes and a flattened attribute to "PaintingInfo" as well, where the relationship is 1:1. In this case it makes sense that deleting a "PaintingFull" should also delete its associated PaintingInfo record.

In this PR a check has been added so that reverse toMany relationships are protected from deletion,
and if a relevant ObjRelationship is present then deletions are deferred to it instead.

@Jugen Jugen force-pushed the fix-deletion-of-entities-from-flattened-attribute branch from bb796b9 to ffa2791 Compare May 8, 2024 13:27
@Jugen
Copy link
Contributor Author

Jugen commented May 8, 2024

This PR is ready for review please.

Copy link
Member

@stariy95 stariy95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jugen Thanks for the PR! I got some thoughts on how we may improve it a bit.

@Jugen Jugen force-pushed the fix-deletion-of-entities-from-flattened-attribute branch from ffa2791 to 4189308 Compare May 9, 2024 17:14
@Jugen
Copy link
Contributor Author

Jugen commented May 9, 2024

Have made all the changes as requested. Note that the changes to RootRowOpProcessor.visitDelete has been slightly modified from the initial PR in order for the restored test to pass. So that was a good thing :-). It's strange though .....

@Jugen Jugen force-pushed the fix-deletion-of-entities-from-flattened-attribute branch from 4189308 to 338920e Compare May 17, 2024 07:00
@Jugen
Copy link
Contributor Author

Jugen commented May 17, 2024

Updated release notes and squashed commits for this PR.

@stariy95 stariy95 merged commit 996ca92 into apache:master May 21, 2024
12 checks passed
@Jugen
Copy link
Contributor Author

Jugen commented May 23, 2024

Now that this has been merged are there steps that I must take to back port this as previously suggested ?

@stariy95
Copy link
Member

@Jugen I'll try to just cherry-pick this commit, and hope that it'll just apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants