datajoint / datajoint-matlab

Relational data pipelines for the science lab
MIT License
42 stars 38 forks source link

del deletes some incorrect entries from downstream tables with renamed foreign keys #362

Closed shenshan closed 3 years ago

shenshan commented 3 years ago

Bug Report

Description

del deletes some unexpected entries from downstream tables when the foreign keys are renamed.

Reproducibility

dj version 3.4.2 maybe also in earlier versions. This was an old bug.

To reproduce, create the following tables: +test/User.m

%{
# 
user_id                     : varchar(12)                   # 
%}

classdef User < dj.Manual
end

+test/Duty.m

%{
schedule:   varchar(32)
---
(monday_on_call) -> test.User(user_id)
%}

classdef Duty < dj.Manual
end

Then insert some data into the tables.

inserti(...
    test.User, ...
    { 'raphael'; 'shan'; 'chris'; 'thinh'})

inserti(...
    test.Duty, {'schedule1', 'shan'; 'schedule2', 'raphael'})

Now delete the user shan, it should delete 1 entry from the test.Duty table, but it tries to delete two entries.

>> del(test.User & 'user_id="shan"')

ABOUT TO DELETE:
       1 tuples from `test`.`user` (manual)
       2 tuples from `test`.`duty` (manual)

Proceed to delete? (yes/no) > 

If there is no renaming of foreign key, the delete was fine.

guzman-raphael commented 3 years ago

@shenshan Thanks for the report. This one is a pre-existing issue and a bit more involved to patch. It is at the top of the current priority and will keep you posted on any updates. There is a comment here in the source about this specifically too.