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
func.sum
may returns Decimal
that break rest APIs.
#15585
Conversation
airflow/models/pool.py
Outdated
session.query(func.sum(TaskInstance.pool_slots)) | ||
.filter(TaskInstance.pool == self.pool) | ||
.filter(TaskInstance.state.in_(list(EXECUTION_STATES))) | ||
.scalar() | ||
) or 0 | ||
) or 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0
does not need to be converted, so I’d just cast the query part:
return int(
session.query(func.sum(TaskInstance.pool_slots))
.filter(TaskInstance.pool == self.pool)
.filter(TaskInstance.state.in_(list(EXECUTION_STATES)))
.scalar()
) or 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uranusjr I tried this first, but failed, when filter matched nothing, it returns None
😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per MySQL doc:
If there are no matching rows, SUM() returns NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh… alright then.
c4fdf77
to
8eaa24d
Compare
Hi @suiting-young , the change makes sense to me. Please fix the static check errors. Thanks |
Which will break APIs for JSON serialization.
8eaa24d
to
fcc3162
Compare
sqlalchemy.func.sum
has a known "issue" that it may returnsDecimal
value (in my case MySQL 5.7).This will cause problem when calling rest APIs. E.g.
@ashb and @kaxil please have a review, thanks!