Skip to content

Commit d5157d0

Browse files
Merge pull request #2 from dimitri-yatsenko/populate-error
fix #902: re-load dependencies after table declaration.
2 parents ec7b2e0 + eb86b41 commit d5157d0

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

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

tests/test_autopopulate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Image(dj.Imported):
8686

8787
def make(self, key):
8888
self.insert1(dict(key, image_data=dict()))
89+
8990
Image.populate()
9091

9192
@schema
@@ -98,4 +99,5 @@ class Crop(dj.Computed):
9899

99100
def make(self, key):
100101
self.insert1(dict(key, crop_image=dict()))
102+
101103
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)