Skip to content

Commit cdc66aa

Browse files
fix: Aggregation and Union __bool__ always returning True (#1234)
The __bool__ methods were returning bool(cursor) instead of bool(cursor.fetchone()[0]), causing them to always return True regardless of whether the query result was empty. Fixes #1234 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent c1b36f0 commit cdc66aa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/datajoint/expression.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,11 @@ def __len__(self):
10391039
).fetchone()[0]
10401040

10411041
def __bool__(self):
1042-
return bool(self.connection.query("SELECT EXISTS({sql})".format(sql=self.make_sql())))
1042+
return bool(
1043+
self.connection.query(
1044+
"SELECT EXISTS({sql})".format(sql=self.make_sql())
1045+
).fetchone()[0]
1046+
)
10431047

10441048

10451049
class Union(QueryExpression):
@@ -1101,7 +1105,11 @@ def __len__(self):
11011105
).fetchone()[0]
11021106

11031107
def __bool__(self):
1104-
return bool(self.connection.query("SELECT EXISTS({sql})".format(sql=self.make_sql())))
1108+
return bool(
1109+
self.connection.query(
1110+
"SELECT EXISTS({sql})".format(sql=self.make_sql())
1111+
).fetchone()[0]
1112+
)
11051113

11061114

11071115
class U:

0 commit comments

Comments
 (0)