diff --git a/CHANGELOG.md b/CHANGELOG.md index bce0d7ccf..739503580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Release notes +### 0.13.3 -- May 28, 2021 +* Bugfix - Dependencies not properly loaded on populate. (#902) PR #919 + ### 0.13.2 -- May 7, 2021 * Update `setuptools_certificate` dependency to new name `otumat` * Bugfix - Explicit calls to `dj.Connection` throw error due to missing `host_input` (#895) PR #907 diff --git a/datajoint/autopopulate.py b/datajoint/autopopulate.py index 9e9615144..c32297028 100644 --- a/datajoint/autopopulate.py +++ b/datajoint/autopopulate.py @@ -39,8 +39,8 @@ def _rename_attributes(table, props): if self._key_source is None: parents = self.target.parents(primary=True, as_objects=True, foreign_key_info=True) if not parents: - raise DataJointError( - 'A relation must have primary dependencies for auto-populate to work') + raise DataJointError('A table must have dependencies ' + 'from its primary key for auto-populate to work') self._key_source = _rename_attributes(*parents[0]) for q in parents[1:]: self._key_source *= _rename_attributes(*q) diff --git a/datajoint/schemas.py b/datajoint/schemas.py index d108caef2..ab2fc03af 100644 --- a/datajoint/schemas.py +++ b/datajoint/schemas.py @@ -23,7 +23,6 @@ def ordered_dir(class_): """ List (most) attributes of the class including inherited ones, similar to `dir` build-in function, but respects order of attribute declaration as much as possible. - This becomes unnecessary in Python 3.6+ as dicts became ordered. :param class_: class to list members for :return: a list of attributes declared in class_ and its superclasses """ @@ -186,6 +185,7 @@ def _decorate_table(self, table_class, context, assert_declared=False): if not self.create_tables or assert_declared: raise DataJointError('Table `%s` not declared' % instance.table_name) instance.declare(context) + self.connection.dependencies.clear() is_declared = is_declared or instance.is_declared # add table definition to the doc string diff --git a/datajoint/version.py b/datajoint/version.py index c5a4541fe..6253805eb 100644 --- a/datajoint/version.py +++ b/datajoint/version.py @@ -1,3 +1,3 @@ -__version__ = "0.13.2" +__version__ = "0.13.3" assert len(__version__) <= 10 # The log table limits version to the 10 characters diff --git a/docs-parts/intro/Releases_lang1.rst b/docs-parts/intro/Releases_lang1.rst index cc5acdb98..2493f6512 100644 --- a/docs-parts/intro/Releases_lang1.rst +++ b/docs-parts/intro/Releases_lang1.rst @@ -1,3 +1,7 @@ +0.13.3 -- May 28, 2021 +---------------------- +* Bugfix - Dependencies not properly loaded on populate. (#902) PR #919 + 0.13.2 -- May 7, 2021 ---------------------- * Update `setuptools_certificate` dependency to new name `otumat` diff --git a/tests/test_autopopulate.py b/tests/test_autopopulate.py index c9cb7f97d..081787670 100644 --- a/tests/test_autopopulate.py +++ b/tests/test_autopopulate.py @@ -1,6 +1,7 @@ from nose.tools import assert_equal, assert_false, assert_true, raises -from . import schema +from . import schema, PREFIX from datajoint import DataJointError +import datajoint as dj class TestPopulate: @@ -64,3 +65,39 @@ def test_allow_insert(self): key['experiment_id'] = 1001 key['experiment_date'] = '2018-10-30' self.experiment.insert1(key) + + def test_load_dependencies(self): + schema = dj.Schema(f'{PREFIX}_load_dependencies_populate') + + @schema + class ImageSource(dj.Lookup): + definition = """ + image_source_id: int + """ + contents = [(0,)] + + @schema + class Image(dj.Imported): + definition = """ + -> ImageSource + --- + image_data: longblob + """ + + def make(self, key): + self.insert1(dict(key, image_data=dict())) + + Image.populate() + + @schema + class Crop(dj.Computed): + definition = """ + -> Image + --- + crop_image: longblob + """ + + def make(self, key): + self.insert1(dict(key, crop_image=dict())) + + Crop.populate() diff --git a/tests/test_erd.py b/tests/test_erd.py index 6c4ae24b7..d1905e418 100644 --- a/tests/test_erd.py +++ b/tests/test_erd.py @@ -26,6 +26,7 @@ def test_decorator(): @staticmethod def test_dependencies(): deps = schema.connection.dependencies + deps.load() assert_true(all(cls.full_table_name in deps for cls in (A, B, B.C, D, E, E.F, L))) assert_true(set(A().children()) == set([B.full_table_name, D.full_table_name])) assert_true(set(D().parents(primary=True)) == set([A.full_table_name])) diff --git a/tests/test_schema_keywords.py b/tests/test_schema_keywords.py index 577524511..50cb25558 100644 --- a/tests/test_schema_keywords.py +++ b/tests/test_schema_keywords.py @@ -3,7 +3,7 @@ from nose.tools import assert_true -schema = dj.Schema(PREFIX + '_keywords', locals(), connection=dj.conn(**CONN_INFO)) +schema = dj.Schema(PREFIX + '_keywords', connection=dj.conn(**CONN_INFO)) @schema