You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Aggregation __bool__ returns True when empty #1234
My intuition regarding projection and aggregation is that they return objects that will behave the same as tables. For an ordinary table, bool(Table) == len(Table) > 0, but this isn't the case for aggregations
Reproducibility
Include:
OS Linux
Python Version: 3.10
MySQL Version: 8 latest
MySQL Deployment Strategy local-docker
DataJoint Version: 0.14.3
Minimum number of steps to reliably reproduce the issue: see below
Complete error stack as a result of evaluating the above steps: n/a
MWE
importdatajointasdjschema=dj.schema("cbroz_temp")
@schemaclassA(dj.Lookup):
definition=""" a_id: int """contents= [[i] foriinrange(1, 3)]
@schemaclassB(dj.Lookup):
definition=""" -> A b_id: int """contents= [(i, j) foriinrange(1, 2) forjinrange(4, 8)]
if__name__=="__main__":
has_entry=A&"a_id=1"no_entry=A&"a_id=3"print("Table with contents as bool: ", bool(has_entry)) # Trueprint("Table without contents as bool: ", bool(no_entry)) # Falseaggr_has_entry=has_entry.aggr(B, b_id="COUNT(b_id)")
aggr_no_entry=no_entry.aggr(B, b_id="COUNT(b_id)")
print("Aggr table with contents as bool: ", bool(aggr_has_entry)) # True print("Aggr table without contents as bool: ", bool(aggr_no_entry)) # True
Expected Behavior
I expected bool(Aggr) == len(Aggr) > 0
Screenshots
n/a
Additional Research and Context
Checked existing issues
Looked at git blame for the relevant code. PR Pre-release 0.13dev2 candidate #850 featured this commit, which chose to make the QueryExpression bool based on length and the Aggregation bool based on it being a valid selection - Is this related to evaluations during cascading delete?
Activity
github-actions commentedon Jun 3, 2025
This issue is stale because it has been open for 45 days with no activity.
github-actions commentedon Jul 19, 2025
This issue is stale because it has been open for 45 days with no activity.
fix: Aggregation and Union __bool__ always returning True (#1234)
fix: Aggregation and Union __bool__ always returning True (#1234)
fix: Aggregation and Union __bool__ always returning True (#1234) (#1314
dimitri-yatsenko commentedon Jan 9, 2026
Fixed in #1314