RangeFilter silently drops a 0 bound
Under which category would you file this issue?
Providers
Apache Airflow version
main
What happened and how to reproduce it?
RangeFilter silently drops a 0 bound. Filtering by duration_gte=0 returns unfiltered results. to_orm in airflow-core/src/airflow/api_fastapi/common/parameters/range.py checks if self.value.lower_bound_gte: instead of is not None, so 0 and 0.0 are skipped. is_active() uses is not None, so the filter still reports itself as active. Same pattern in NullableDatetimeRangeFilter.to_orm.
Call GET /api/v2/dags/{dag_id}/dagRuns?duration_gte=0. The response includes runs of any duration, the filter is ignored. Same with duration_lte=0, and with max_active_runs_gte=0 on the backfills endpoint.
What you think should happen instead?
No response
Operating System
No response
Deployment
None
Apache Airflow Provider(s)
No response
Versions of Apache Airflow Providers
No response
Official Helm Chart version
Not Applicable
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
No response
Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
Thanks for opening this issue, @KUMAR-AKASH-M! I'd really like to pick it up.
I've looked into the problem and would like to investigate why zero-valued bounds are being ignored in RangeFilter and NullableDatetimeRangeFilter, and add tests to cover the fix.
Please let me know if anyone is already working on this or if there's anything specific you'd like me to focus on. I'd be happy to get started and submit a PR soon
Hi, thanks for offering. This one is already being fixed in #77597, so no need to start on it.
Thanks for the clear report. While triaging the three open PRs against main:
All three apply the same fix — truthiness → is not None in both to_orm implementations (the range.py diff is byte-identical), which brings to_orm back in line with what is_active() already checks. So the merge decision mainly comes down to test coverage, and the three differ meaningfully there:
- #77605 is the most complete: it covers both filter classes, goes through the
int/floatfactory functions (which is how every route actually builds these filters), exercises SQLite row filtering including NULL rows, and adds a route-level regression formax_active_runs_lte=0. It's also the only one carryingCloses: #77591for auto-close. - #77597 has the most behavior-faithful unit test (real in-memory SQLite, asserts actual returned row values, and is the only one covering the combined
lower_bound_gte=0.0 + upper_bound_lte=0.0case), but it only covers theRangeFilterbase class — neither theNullableDatetimeRangeFilteroverride nor the factory path. - #77629 is the smallest diff with a clean parametrization over bound kind and column type, but only asserts compiled SQL text, and likewise doesn't cover
NullableDatetimeRangeFilteror the factories. It is also still marked as draft, for whoever is comparing the three.
One observation for whoever merges: the NullableDatetimeRangeFilter.to_orm change is defensive consistency only. Its bounds always come from the datetime factories, which parse query strings through _safe_parse_datetime_optional, so a zero bound can never reach that class from a real request (cf. the int/float factories where 0 is a legitimate value). Including it is fine and keeps the two methods symmetric, but it's worth knowing when reading the tests — e.g. passing 0 to the datetime variant exercises a path the API can't actually produce.