datajoint-matlab
datajoint-matlab copied to clipboard
table classes on path was not recognized when deleting or populating
Bug Report
Description
Some table class is on path, e.g. table test2.Downstream, but when deleting from an upstream table in a different schema, e.g. table test.Upstream, the entries in test2.Downstream would not be detected. If in the command window, we print out test2.Downstream
, it will properly get deleted when deleting test.Upstream. Similar behavior happens when populating the downstream table. So I think they might be the same issue.
Reproducibility
dj version 3.4.2, but it probably happened in earlier versions as well.
To reproduce, create the following tables: +test/Upstream.m
%{
up_id : tinyint
%}
classdef Upstream < dj.Manual
end
+test2/Downstream.m
%{
-> test.Upstream
%}
classdef Downstream < dj.Computed
methods(Access=protected)
function makeTuples(self, key)
self.insert(key)
end
end
end
Now insert an entry in Upstream:
insert(test.Upstream, {1})
Then we do clear all
and then populate Downstream table:
>> clear all
>> populate(test2.Downstream)
0: Localhost via UNIX socket Server version 5.5.5-10.4.13-MariaDB
Error using dj.internal.Table/set.className (line 70)
invalid table identification '`test`.`upstream`'. Should be package.ClassName
Error in dj.internal.Table (line 46)
self.className = className;
Error in dj.Relvar (line 13)
[email protected](varargin{:})
Error in dj.internal.AutoPopulate>@(ix)dj.Relvar(self.schema.conn.tableToClass(parents{ix})) (line 76)
r = @(ix) dj.Relvar(self.schema.conn.tableToClass(parents{ix}));
Error in dj.internal.AutoPopulate/getKeySource (line 77)
source = r(1);
Error in dj.internal.AutoPopulate/populateSanityChecks (line 444)
source = self.getKeySource;
Error in dj.internal.AutoPopulate/populate (line 128)
rels{i}.populateSanityChecks
If print test.Upstream first, then it works:
>> test.Upstream
ans =
Object test.Upstream
:: ::
UP_ID
_____
1
1 tuples (0.498 s)
>> populate(test2.Downstream)
**test2.Downstream: Found 1 unpopulated keys
Populating test2.Downstream for:
up_id: 1
Now both tables have one entry. clear all now.
clear all
Then delete from Upstream table:
>> del(test.Upstream)
0: Localhost via UNIX socket Server version 5.5.5-10.4.13-MariaDB
ABOUT TO DELETE:
1 tuples from `test`.`upstream` (manual)
Proceed to delete? (yes/no) > yes
Deleting from test.Upstream
** delete rolled back due to an error
Error using mym
Cannot delete or update a parent row: a foreign key constraint fails (`test2`.`__downstream`, CONSTRAINT `P14Ktde1`
FOREIGN KEY (`up_id`) REFERENCES `test`.`upstream` (`up_id`) ON UPDATE CASCADE)
Error in dj.Connection/query (line 185)
mym(self.connId, queryStr, v{:});
Error in dj.Relvar/delQuick (line 27)
self.schema.conn.query(sprintf('DELETE FROM %s', self.sql))
Error in dj.Relvar/del (line 120)
rel.delQuick;
If print out test2.Downstream first, it works:
>> test2.Downstream
ans =
Object test2.Downstream
:: ::
UP_ID
_____
1
1 tuples (0.221 s)
>> del(test.Upstream)
ABOUT TO DELETE:
1 tuples from `test`.`upstream` (manual)
1 tuples from `test2`.`__downstream` (computed)
Proceed to delete? (yes/no) > yes
Deleting from test2.Downstream
Deleting from test.Upstream
committed