Skip to content

Commit d4fb01d

Browse files
Merge pull request #919 from guzman-raphael/populate-error
Fix dependency load issue on populate
2 parents 9ef06f9 + fe58bc6 commit d4fb01d

File tree

8 files changed

+51
-6
lines changed

8 files changed

+51
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Release notes
22

3+
### 0.13.3 -- May 28, 2021
4+
* Bugfix - Dependencies not properly loaded on populate. (#902) PR #919
5+
36
### 0.13.2 -- May 7, 2021
47
* Update `setuptools_certificate` dependency to new name `otumat`
58
* Bugfix - Explicit calls to `dj.Connection` throw error due to missing `host_input` (#895) PR #907

datajoint/autopopulate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def _rename_attributes(table, props):
3939
if self._key_source is None:
4040
parents = self.target.parents(primary=True, as_objects=True, foreign_key_info=True)
4141
if not parents:
42-
raise DataJointError(
43-
'A relation must have primary dependencies for auto-populate to work')
42+
raise DataJointError('A table must have dependencies '
43+
'from its primary key for auto-populate to work')
4444
self._key_source = _rename_attributes(*parents[0])
4545
for q in parents[1:]:
4646
self._key_source *= _rename_attributes(*q)

datajoint/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def ordered_dir(class_):
2323
"""
2424
List (most) attributes of the class including inherited ones, similar to `dir` build-in function,
2525
but respects order of attribute declaration as much as possible.
26-
This becomes unnecessary in Python 3.6+ as dicts became ordered.
2726
:param class_: class to list members for
2827
:return: a list of attributes declared in class_ and its superclasses
2928
"""
@@ -186,6 +185,7 @@ def _decorate_table(self, table_class, context, assert_declared=False):
186185
if not self.create_tables or assert_declared:
187186
raise DataJointError('Table `%s` not declared' % instance.table_name)
188187
instance.declare(context)
188+
self.connection.dependencies.clear()
189189
is_declared = is_declared or instance.is_declared
190190

191191
# add table definition to the doc string

datajoint/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.13.2"
1+
__version__ = "0.13.3"
22

33
assert len(__version__) <= 10 # The log table limits version to the 10 characters

docs-parts/intro/Releases_lang1.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.13.3 -- May 28, 2021
2+
----------------------
3+
* Bugfix - Dependencies not properly loaded on populate. (#902) PR #919
4+
15
0.13.2 -- May 7, 2021
26
----------------------
37
* Update `setuptools_certificate` dependency to new name `otumat`

tests/test_autopopulate.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from nose.tools import assert_equal, assert_false, assert_true, raises
2-
from . import schema
2+
from . import schema, PREFIX
33
from datajoint import DataJointError
4+
import datajoint as dj
45

56

67
class TestPopulate:
@@ -64,3 +65,39 @@ def test_allow_insert(self):
6465
key['experiment_id'] = 1001
6566
key['experiment_date'] = '2018-10-30'
6667
self.experiment.insert1(key)
68+
69+
def test_load_dependencies(self):
70+
schema = dj.Schema(f'{PREFIX}_load_dependencies_populate')
71+
72+
@schema
73+
class ImageSource(dj.Lookup):
74+
definition = """
75+
image_source_id: int
76+
"""
77+
contents = [(0,)]
78+
79+
@schema
80+
class Image(dj.Imported):
81+
definition = """
82+
-> ImageSource
83+
---
84+
image_data: longblob
85+
"""
86+
87+
def make(self, key):
88+
self.insert1(dict(key, image_data=dict()))
89+
90+
Image.populate()
91+
92+
@schema
93+
class Crop(dj.Computed):
94+
definition = """
95+
-> Image
96+
---
97+
crop_image: longblob
98+
"""
99+
100+
def make(self, key):
101+
self.insert1(dict(key, crop_image=dict()))
102+
103+
Crop.populate()

tests/test_erd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_decorator():
2626
@staticmethod
2727
def test_dependencies():
2828
deps = schema.connection.dependencies
29+
deps.load()
2930
assert_true(all(cls.full_table_name in deps for cls in (A, B, B.C, D, E, E.F, L)))
3031
assert_true(set(A().children()) == set([B.full_table_name, D.full_table_name]))
3132
assert_true(set(D().parents(primary=True)) == set([A.full_table_name]))

tests/test_schema_keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from nose.tools import assert_true
44

55

6-
schema = dj.Schema(PREFIX + '_keywords', locals(), connection=dj.conn(**CONN_INFO))
6+
schema = dj.Schema(PREFIX + '_keywords', connection=dj.conn(**CONN_INFO))
77

88

99
@schema

0 commit comments

Comments
 (0)