Repository navigation
fix(query): restricting by a union no longer raises TypeError - #1755
Open
dimitri-yatsenko wants to merge 1 commit into
Open
dimitri-yatsenko wants to merge 1 commit into
dimitri-yatsenko wants to merge 1 commit into
Conversation
Restricting by a union raised TypeError because Union.make_sql takes no field list. A union with secondary attributes restricts its right operand by its left one, so a union whose left operand is a union failed the same way when fetched or counted. make_condition now wraps a union operand in a subquery, as it already does for an aggregation or a dj.Top-limited expression. Fixes #1739
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
November 24, 2026 21:38
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1739
What changes
Restricting by a union raised
TypeError: Union.make_sql() takes 1 positional argument but 2 were given. This affected:A & (B + C)andA - (B + C)len(), or use as a restriction. Such a union compilesarg2 - arg1, which restricts by the left operand.make_conditionnow wraps a union operand in a subquery before building theIN (...)condition, as it already does for an aggregation or adj.Top-limited expression. Two lines change insrc/datajoint/condition.py.No change for queries that work today
Every code path changed here raised before, so no query that runs today returns a different result. A union with no attributes in common with the restricted query still takes the existing true/false shortcut. A new test covers that case and passes before and after the change.
Relation to the 2.4 fix
NOT EXISTS) and raises the minimum MySQL version.Unionimport and theisinstance(condition, (Aggregation, Union))check, with the same text as 1663.git merge-treeshows no conflicts between this branch and 1663, or between this branch andnext.NOT EXISTSform, and the expected results stay the same because the test data has no NULL keys.Tests
New
tests/integration/test_union_restriction.py, run on MySQL and PostgreSQL:len()The full suite passes on both backends.