diff --git a/datajoint/relational_operand.py b/datajoint/relational_operand.py index 9e98fd1e9..293cbce38 100644 --- a/datajoint/relational_operand.py +++ b/datajoint/relational_operand.py @@ -301,7 +301,7 @@ def __init__(self, arg, *attributes, **renamed_attributes): else: self._attributes.append(attribute) - if arg.heading.computed: + if arg.heading.computed or arg.restrictions: self._arg = Subquery(arg) else: self._arg = arg diff --git a/tests/test_relational_operand.py b/tests/test_relational_operand.py index f7851dc72..a6c19a46e 100644 --- a/tests/test_relational_operand.py +++ b/tests/test_relational_operand.py @@ -216,6 +216,18 @@ def test_project(): assert_equal(set(x.heading.names), set(('id_a', 'a')), 'extend does not work') + # projection after restriction + assert_equal( + len(D() & (L() & 'cond_in_l')) + len(D() - (L() & 'cond_in_l')), + len(D()), + 'failed semijoin or antijoin' + ) + assert_equal( + len((D() - (L() & 'cond_in_l')).project()), + len(D() - (L() & 'cond_in_l')), + 'projection altered the cardinality of a restricted relation' + ) + @staticmethod def test_aggregate(): x = B().aggregate(C(), 'n', count='count(id_c)', mean='avg(value)', max='max(value)')