datajoint / datajoint-matlab

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

bug with del() #379

Closed arsenyf closed 2 years ago

arsenyf commented 3 years ago

When attempting to delete I get the following error:

del(EXP2.Session & 'subject_id=481102') Error using ~ Too many input arguments.

Error in dj.Relvar/del (line 95) if ~fks.aliased

'subject_id' is the primary key for table EXP2.Session, and this always worked before. I noticed it after upgrading to DataJoint version 3.4.3. del() with few other tables that are under EXP2.Session with the same key that I tested worked fine

MATLAB 2018b DataJoint version 3.4.3

bug
kabilar commented 3 years ago

@kabilar @alvalunasan

Alvalunasan commented 2 years ago

Do we have any updates on this ? Our team here in Princeton has been facing this issue a lot now. Thanks

kabilar commented 2 years ago

Hi @Alvalunasan, thanks for the report. After discussion with @guzman-raphael, the team will be able to return to this issue within 2-3 weeks.

zfj1 commented 2 years ago

Just commenting here since this hasn't had any traction in a while. I believe this issue can be resolved with an edit to a single line of code, as in https://github.com/datajoint/datajoint-matlab/pull/380/commits/938626cb412c635770cc3912f59660e4e009cc61. This probably arose in the most recent release because of weak typing in MATLAB and testing against a table with only one foreign key. I haven't checked that the rest of the logic there is sound, but if you read the comments it's obvious this is what they were going for. So as a workaround before this gets formally addressed you should just be able to edit that line in your datajoint installation.

Alvalunasan commented 2 years ago

Example of an incorrect deletion on version 3.4.2 table lab.DutyRoaster: (lab.User as foreign key many times)

%{
duty_roaster_date:  date       # date from which this assignment is valid.
----- 
(monday_duty)    -> lab.User(user_id)
(tuesday_duty)   -> lab.User(user_id)
(wednesday_duty) -> lab.User(user_id)
.
.
%}

testtech_del1 is a reference only for record 2 {'2021-03-11'}

lab.DutyRoaster

    DUTY_ROASTER_DATE       monday_duty         tuesday_duty        wednesday_duty      ...   
    _________________    _________________    _________________    _________________    ...

     {'2021-03-10'}      {'jrw10'        }    {'baptista'     }    {'jrw10'        }    ...
     {'2021-03-11'}      {'testtech_del1'}    {'testtech_del2'}    {'testtech_del1'}    ...

We try to delete that user it tries to delete all records from duty_roaster :

key.user_id = 'testtech_del1'
del(lab.User & key)

ABOUT TO DELETE:
       1 tuples from `u19_lab`.`user` (manual)
       2 tuples from `u19_lab`.`duty_roaster` (manual)
kabilar commented 2 years ago

Thanks @Alvalunasan. I will adapt your example for a test case.

Schema diagram

image

Table definitions

lab.User

%{
user_id: varchar(32)
%}

classdef User < dj.Manual
end

lab.Duty

%{
duty_date:  date
----- 
(duty_first)    -> lab.User(user_id)
(duty_second)    -> lab.User(user_id)
%}

classdef Duty < dj.Manual
end

Insert table entries

users = [{'user0'
          'user1'
          'user2'}]

insert(lab.User, users)

duty = [{'2020-01-01','user0','user1'},
        {'2020-12-31','user1','user2'}]

insert(lab.Duty, duty)

Table entries

lab.User()

     USER_ID 
    _________

    {'user0'}
    {'user1'}
    {'user2'}
lab.Duty()

      DUTY_DATE       duty_first    duty_second
    ______________    __________    ___________

    {'2020-01-01'}    {'user0'}      {'user1'} 
    {'2020-12-31'}    {'user1'}      {'user2'} 

Test case 1 with DataJoint MATLAB 3.4.2

Versions

MATLAB R2020b DataJoint MATLAB 3.4.2 mym 2.8.2

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

Proceed to delete? (yes/no) > yes Deleting from lab.Duty Deleting from lab.User committed

lab.Duty() 0 tuples


## Test case 2 with DataJoint MATLAB 3.4.3
### Versions
MATLAB R2020b
DataJoint MATLAB 3.4.3
mym 2.8.2

- Deleting `user0` in lab.User, throws an error.

key.user_id = 'user0'; del(lab.User & key)

Error using ~ Too many input arguments.

Error in dj.Relvar/del (line 95) if ~fks.aliased