-
Notifications
You must be signed in to change notification settings - Fork 38
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
Cascading delete fails with non-congruent non-pk foreign refs #46
Comments
I think the problem can be reduced to a simpler one: delete(test.Monkey & 'image_id=2') will fail because datajoint does not cascade deletes up the hierarchy by design. I think the error above is expected behavior. However, we need to improve the documentation. |
I changed the title of the issue because it gave the impression that erroneous deletes were performed. Failure to delete due to a referential constraint is expected behavior. |
I obviously didn't get back to this issue for quite some time, but no, this issue was not caused by erroneous cascading up the hierarchy but rather by incorrect cascading down of the restriction down the hierarchy chain, and this is certainly not the expected behavior. Now that we have modified a lot of things in DataJoint, it'll be good to test whether this is still an issue. |
I have just verified that this issue still remains in MATLAB (but haven't tested in Python). Basically in the following code snippet from Lines 74 to 84 in e4fe19b
for i=1:length(rels)
% iterate through all tables that reference rels(i)
for ix = cellfun(@(child) find(strcmp(self.schema.conn.tableToClass(child),list)), rels(i).children)
% and restrict them by it or its restrictions
if restrictByMe(i)
rels(ix).restrict(pro(rels(i))) % TODO: handle renamed attributes self.conn.foreignKeys(fullTableName).aliased
else
rels(ix).restrict(rels(i).restrictions{:});
end
end
end the restrictions are ANDed whereas the correct thing to do is to OR every restriction path. |
Follow set of tables lead to incorrect cascading delete:
Image
MonkeyImage
ModifiedMonkeyImage
In the above three tables,
Image
is where all the images are actually stored aslongblob
, with each image given a uniqueimage_id
.MonkeyImage
is a convenient collection of all images for monkeys, with unique entry for each monkey identified bysubj_id
. Finally,ModifiedMonkeyImage
is a collection of modified images for the monkey, uniquely identified by thesubj_id
of the monkey as themodification_type
descriptor. Note that althoughModifiedMonkeyImage
is a child ofMonkeyImage
and that both have non-pk foreign ref back toImage
, they will point to different image entries!With the three tables defined as above, the follow code illustrates the issue:
This issue has been mentioned on datajoint/datajoint-python#15 and I am not sure if it has been appropriately dealt with in datajoint-python either. This is caused by an inappropriate cascading when there exists multiple paths from a parent table (e.g.
Image
) to the target (ModifiedMonkeyImage
, here paths areImage -> ModifiedMonkeyImage
andImage -> MonkeyImage -> ModifiedMonkeyImage
).The text was updated successfully, but these errors were encountered: