Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependency load issue on populate #919

Merged
merged 4 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions datajoint/autopopulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion datajoint/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion datajoint/version.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docs-parts/intro/Releases_lang1.rst
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
39 changes: 38 additions & 1 deletion tests/test_autopopulate.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions tests/test_erd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down