You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Jurgen Doll <ju...@ivoryemr.co.za> on 2024/05/01 10:29:28 UTC

Deleting ObjEntity with flattened attribute

Hi All

I've recently upgraded from Cayenne 3.1 to 4.2 and noticed that when  
deleting an ObjEntity with flattened attributes Cayenne now 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 is still deleted.

I would submit a bug report and PR to fix but looking at the code [1] and  
tests [2] I was surprised to find that the behavior of the first example  
appears to be intentional which is why I'm writing this email.

Unless I'm missing something I would like to submit said bug report and PR  
to revert this to either 3.1 behavior (no cascade delete) or a modified  
version of the current behavior.

I think 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.

If there's no objection I could try and add a check for this and only do  
the delete if the relationship is 1:1 and there's no relationship  
attribute with delete rule Deny. If it's too complicated I'd just revert  
the current behavior to 3.1

Thoughts please.

Thanks, regards
Jurgen

[1] RootRowOpProcessor.visitDelete
[2] DataContextFlattenedAttributesIT.testDelete

Re: Deleting ObjEntity with flattened attribute

Posted by Jurgen Doll <ju...@ivoryemr.co.za>.
Hi Nikita

I've submitted a PR to fix the issue and the test case.

I did have a look at using trackedFlattenedPaths as you suggested but  
preventing a flattened attribute from being added then also prevents any  
updates to those attributes from being properly committed. So I had to use  
an alternative method.

Thanks, regards
Jurgen


On Mon, 06 May 2024 16:22:48 +0200, Nikita Timofeev  
<nt...@objectstyle.com> wrote:

> Hi Jurgen,
>
> Yeah, this seems like a problem here, thanks for finding it.
>
> Delete part is indeed intended behavior and introduced some time ago (I'm
> not quite sure when),
> and Cayenne 4.2 had a significant refactoring that altered the overall
> logic of flattened relationships.
> The idea here is that the main object tracks and manages all related
> flattened objects, otherwise they could just clutter the DB.
>
> So reverting to a 3.1 logic is not an option here unfortunately.
>
> We could (and probably should) get smarter logic that decides if we need  
> to
> delete a flattened row.
> Looking at the code, we may need to change not the delete part, but  
> rather
> the tracking part (e.g. what goes to the  
> ObjectStore.trackedFlattenedPaths)
>
> Would be great if you could provide a test case for this.

Re: Deleting ObjEntity with flattened attribute

Posted by Nikita Timofeev <nt...@objectstyle.com>.
Hi Jurgen,

Yeah, this seems like a problem here, thanks for finding it.

Delete part is indeed intended behavior and introduced some time ago (I'm
not quite sure when),
and Cayenne 4.2 had a significant refactoring that altered the overall
logic of flattened relationships.
The idea here is that the main object tracks and manages all related
flattened objects, otherwise they could just clutter the DB.

So reverting to a 3.1 logic is not an option here unfortunately.

We could (and probably should) get smarter logic that decides if we need to
delete a flattened row.
Looking at the code, we may need to change not the delete part, but rather
the tracking part (e.g. what goes to the ObjectStore.trackedFlattenedPaths)

Would be great if you could provide a test case for this.