You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "hkc-8010 (via GitHub)" <gi...@apache.org> on 2026/05/11 06:39:30 UTC
[PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
hkc-8010 opened a new pull request, #66696:
URL: https://github.com/apache/airflow/pull/66696
## Summary
- `datetime_range_filter_factory` wrapped `start_date` and `end_date` columns in
`COALESCE(column, now())` to treat currently-running tasks (NULL date) as "now".
This form prevents PostgreSQL from using btree indexes, causing parallel sequential
scans across the full `task_instance` table even for narrow date windows.
- Replace with explicit OR conditions that are semantically equivalent:
`(col >= X) OR (col IS NULL AND now() >= X)`
PostgreSQL can use a btree index on each OR branch via BitmapOr. Running tasks
(NULL `end_date` / `start_date`) continue to match date-range queries correctly.
- Adds `NullableDatetimeRangeFilter` subclass of `RangeFilter` for the new logic.
`datetime_range_filter_factory` returns this subclass for `start_date` / `end_date`
and a plain `RangeFilter` for all other filter names.
## Performance
Measured against a 4.6M-row `task_instance` table with an `end_date` btree index:
| | Plan | Cost (first 1000 rows) |
|---|---|---|
| Before | Parallel Index Scan + Gather Merge (COALESCE wraps column) | 19,523 |
| After | Single Index Scan, stops early via LIMIT (OR branches) | 2,658 |
**7.4x reduction in query cost.**
Note: vanilla Airflow does not ship an `end_date` index by default. The OR form is
the correct architectural fix regardless. Any deployment that adds an `end_date` index
(via a migration) will immediately benefit. A follow-up migration to add the index is
recommended but is outside the scope of this PR.
## Changes
- `airflow-core/src/airflow/api_fastapi/common/parameters.py`: add
`NullableDatetimeRangeFilter`; update `datetime_range_filter_factory`
- `airflow-core/tests/unit/api_fastapi/common/test_parameters.py`: add
`TestDatetimeRangeFilterFactory` (7 tests covering type dispatch, SQL shape,
no-COALESCE assertion, and NULL-branch presence)
## PR Checklist
- [x] My PR is targeted at the `main` branch
- [x] Tests added (31 pass locally and in Breeze core-tests, Python 3.10 / SQLite)
- [x] `prek` hooks all pass (ruff, ruff-format, mypy)
- [ ] Newsfragment -- will add after PR number is assigned
closes: #66335
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #66696:
URL: https://github.com/apache/airflow/pull/66696#issuecomment-4476281881
@hkc-8010 — There is 1 unresolved review thread on this PR from @ashb, and you have engaged with each one (post-review commits and/or in-thread replies). Could you confirm whether you believe the feedback is fully addressed and the PR is ready for maintainer review confirmation?
If yes, reply here (a short "yes / ready" is fine) and an Apache Airflow maintainer will pick the PR up from the review queue on the next sweep.
If you are still working on a thread, please reply with what is outstanding so the threads stay unresolved on purpose.
---
_Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this [two-stage triage process](https://github.com/apache/airflow/blob/main/contributing-docs/25_maintainer_pr_triage.md#why-the-first-pass-is-automated) so that our maintainers' limited time is spent where it matters most: the conversation with you._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "hkc-8010 (via GitHub)" <gi...@apache.org>.
hkc-8010 commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3218185191
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
)
+class NullableDatetimeRangeFilter(RangeFilter):
+ """
+ RangeFilter for nullable datetime columns that preserves NULL-as-now semantics.
+
+ Uses explicit OR conditions instead of COALESCE(column, now()) so PostgreSQL
+ can use btree indexes on each branch via BitmapOr plans rather than forcing
+ a full table scan.
+ """
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None:
+ return select
Review Comment:
Deliberate. It follows the same pattern as the parent `RangeFilter` class. `value is None` here means the filter block was not requested at all (i.e., no bounds were passed in), not "filter WHERE attribute IS NULL". Since all bounds are typed `datetime | None` at the HTTP layer, the only way `value` is `None` is if the caller constructs the filter object without a `Range`, which doesn't happen via the factory. The IS NULL coverage for running tasks is already embedded in the OR branches below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3217564639
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
)
+class NullableDatetimeRangeFilter(RangeFilter):
+ """
+ RangeFilter for nullable datetime columns that preserves NULL-as-now semantics.
+
+ Uses explicit OR conditions instead of COALESCE(column, now()) so PostgreSQL
+ can use btree indexes on each branch via BitmapOr plans rather than forcing
+ a full table scan.
+ """
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None:
+ return select
Review Comment:
It's probably nothing/not possible to hit over an HTTP api, but this feels like this doesn't let us explicitly filter for this value not being set, and `value is None` could be a ` where(self.attribute.is_(None)` thing?
Maybe ignore me, but if it's delibarate we don't allow that explicitly say so.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "hkc-8010 (via GitHub)" <gi...@apache.org>.
hkc-8010 commented on PR #66696:
URL: https://github.com/apache/airflow/pull/66696#issuecomment-4443472117
Both issues from the code review above have been addressed in the latest push (commit 2ff659c1173):
**Issue 1 — lower-bound `now()` guard removed**
Lower bounds now use `or_(col >= x, col.is_(None))` with no `func.now()` call. A task with NULL `start_date` passes any lower-bound filter unconditionally, which is the correct semantic: a not-yet-started task will eventually start at or after any past bound.
**Issue 2 — factory dispatch fixed for aliased filter names**
The dispatch condition changed from `filter_name in ("start_date", "end_date")` to `(attribute_name or filter_name) in ("start_date", "end_date")`. Callers that pass an aliased `filter_name` with `attribute_name="start_date"` or `attribute_name="end_date"` (e.g. the DAGs endpoint using `"dag_run_end_date"`) now correctly receive `NullableDatetimeRangeFilter` rather than a plain `RangeFilter`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "hkc-8010 (via GitHub)" <gi...@apache.org>.
hkc-8010 commented on PR #66696:
URL: https://github.com/apache/airflow/pull/66696#issuecomment-4443217234
### Code review
Found 2 issues:
1. Lower-bound NULL branch still includes `func.now() >= x`, which breaks filter semantics for future-scheduled tasks. For a lower bound, a task with `NULL start_date` (not yet started) should unconditionally pass — its eventual value will always be >= any past bound. With `now() >= x`, if `x` is in the future, `now() >= x` is `FALSE`, so future-scheduled tasks are incorrectly excluded. Reviewer `ashb` explicitly called this out and suggested `or_(self.attribute.is_(None), self.attribute >= x)` for lower bounds. The author's reply acknowledges this, but the code and the test `test_lower_bound_calls_now_for_running_tasks` (which asserts `"now()"` still appears in lower-bound SQL) contradict the claimed fix.
https://github.com/apache/airflow/blob/315d94d5027896259d30450b7c5a6712874d694e/airflow-core/src/airflow/api_fastapi/common/parameters.py#L907-L916
2. The factory dispatch `if filter_name in ("start_date", "end_date")` checks the API-facing filter name, not the resolved attribute name. Callers in `dags.py` pass aliased names (`"dag_run_start_date"`, `"dag_run_end_date"`) with `attribute_name="start_date"` / `"end_date"`, so they fall through to a plain `RangeFilter`. Since `DagRun.end_date` is `NULL` for running DAGs, these callers silently miss the index-friendly optimization and the correct NULL semantics. The test `test_attribute_name_alias_returns_plain_range_filter` asserts this as correct behavior, but that contradicts the PR's stated goal. The fix from a previous iteration of this PR (`attribute_name or filter_name`) would cover these callers.
https://github.com/apache/airflow/blob/315d94d5027896259d30450b7c5a6712874d694e/airflow-core/src/airflow/api_fastapi/common/parameters.py#L938-L945
🤖 Generated with [Claude Code](https://claude.ai/code)
<sub>- If this code review was useful, please react with 👍. Otherwise, react with 👎.</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "hkc-8010 (via GitHub)" <gi...@apache.org>.
hkc-8010 commented on PR #66696:
URL: https://github.com/apache/airflow/pull/66696#issuecomment-4476352846
The PR is ready for review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "vatsrahul1001 (via GitHub)" <gi...@apache.org>.
vatsrahul1001 commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3217468437
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -908,17 +937,15 @@ def depends_datetime(
upper_bound_lt: datetime | None = Query(alias=f"{filter_name}_lt", default=None),
) -> RangeFilter:
attr = getattr(model, attribute_name or filter_name)
- if filter_name in ("start_date", "end_date"):
- attr = func.coalesce(attr, func.now())
- return RangeFilter(
- Range(
- lower_bound_gte=lower_bound_gte,
- lower_bound_gt=lower_bound_gt,
- upper_bound_lte=upper_bound_lte,
- upper_bound_lt=upper_bound_lt,
- ),
- attr,
+ range_val = Range(
+ lower_bound_gte=lower_bound_gte,
+ lower_bound_gt=lower_bound_gt,
+ upper_bound_lte=upper_bound_lte,
+ upper_bound_lt=upper_bound_lt,
)
+ if filter_name in ("start_date", "end_date"):
Review Comment:
Here we are only resolving column by `filter_name`. We should do by attribute_name or filter_name like we are doing above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3217575378
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
)
+class NullableDatetimeRangeFilter(RangeFilter):
+ """
+ RangeFilter for nullable datetime columns that preserves NULL-as-now semantics.
+
+ Uses explicit OR conditions instead of COALESCE(column, now()) so PostgreSQL
+ can use btree indexes on each branch via BitmapOr plans rather than forcing
+ a full table scan.
+ """
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None:
+ return select
+
+ if self.value.lower_bound_gte:
+ x = self.value.lower_bound_gte
+ select = select.where(or_(self.attribute >= x, and_(self.attribute.is_(None), func.now() >= x)))
+ if self.value.lower_bound_gt:
+ x = self.value.lower_bound_gt
+ select = select.where(or_(self.attribute > x, and_(self.attribute.is_(None), func.now() > x)))
+ if self.value.upper_bound_lte:
+ x = self.value.upper_bound_lte
+ select = select.where(or_(self.attribute <= x, and_(self.attribute.is_(None), func.now() <= x)))
+ if self.value.upper_bound_lt:
+ x = self.value.upper_bound_lt
+ select = select.where(or_(self.attribute < x, and_(self.attribute.is_(None), func.now() < x)))
Review Comment:
If we are looking to optimize: if lower and upper bound is set, can we use `BETWEEN`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "hkc-8010 (via GitHub)" <gi...@apache.org>.
hkc-8010 commented on PR #66696:
URL: https://github.com/apache/airflow/pull/66696#issuecomment-4422674066
The failed check is `CI image checks / Publish documentation and validate versions`, and it looks unrelated to this change. It failed while cloning `apache/airflow-site` with a GitHub-side 500:
`fatal: unable to access 'https://github.com/apache/airflow-site.git/': The requested URL returned error: 500`
Failing job:
https://github.com/apache/airflow/actions/runs/25672761656/job/75372288729
This looks like transient infra/docs publish fallout rather than a regression from this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "hkc-8010 (via GitHub)" <gi...@apache.org>.
hkc-8010 commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3218186752
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
)
+class NullableDatetimeRangeFilter(RangeFilter):
+ """
+ RangeFilter for nullable datetime columns that preserves NULL-as-now semantics.
+
+ Uses explicit OR conditions instead of COALESCE(column, now()) so PostgreSQL
+ can use btree indexes on each branch via BitmapOr plans rather than forcing
+ a full table scan.
+ """
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None:
+ return select
+
+ if self.value.lower_bound_gte:
+ x = self.value.lower_bound_gte
+ select = select.where(or_(self.attribute >= x, and_(self.attribute.is_(None), func.now() >= x)))
Review Comment:
Good point, accepted for lower bounds. For a lower bound on a nullable column, a NULL value (task still running / not yet started) satisfies the filter unconditionally — its eventual value will be >= any past bound — so `(col >= x) OR (col IS NULL)` is sufficient and cleaner.
Upper bounds are a different story. For `end_date <= X`, we only want to include running tasks (NULL end_date) if the window extends to the present or future, so the `NOW() <= x` guard is meaningful there: filtering `end_date_lte=2020-01-01` should not return tasks still running in 2026.
Updated the lower bounds to use your suggestion, kept the upper bounds as-is, and added tests to pin both behaviors.
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
)
+class NullableDatetimeRangeFilter(RangeFilter):
+ """
+ RangeFilter for nullable datetime columns that preserves NULL-as-now semantics.
+
+ Uses explicit OR conditions instead of COALESCE(column, now()) so PostgreSQL
+ can use btree indexes on each branch via BitmapOr plans rather than forcing
+ a full table scan.
+ """
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None:
+ return select
+
+ if self.value.lower_bound_gte:
+ x = self.value.lower_bound_gte
+ select = select.where(or_(self.attribute >= x, and_(self.attribute.is_(None), func.now() >= x)))
+ if self.value.lower_bound_gt:
+ x = self.value.lower_bound_gt
+ select = select.where(or_(self.attribute > x, and_(self.attribute.is_(None), func.now() > x)))
+ if self.value.upper_bound_lte:
+ x = self.value.upper_bound_lte
+ select = select.where(or_(self.attribute <= x, and_(self.attribute.is_(None), func.now() <= x)))
+ if self.value.upper_bound_lt:
+ x = self.value.upper_bound_lt
+ select = select.where(or_(self.attribute < x, and_(self.attribute.is_(None), func.now() < x)))
Review Comment:
BETWEEN would still need the same OR IS NULL branches on each side, so the SQL ends up equivalent to what we have now. It also only covers the inclusive `>= ... <=` case; the exclusive `>= ... <` variant (used in some callers) would need separate handling. The two separate WHERE clauses already produce the optimal BitmapOr plan — BETWEEN wouldn't simplify the generated SQL or help the planner further.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #66696:
URL: https://github.com/apache/airflow/pull/66696#issuecomment-4476715108
### Backport successfully created: v3-2-test
Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>✅</td>
<td>v3-2-test</td>
<td><a href="https://github.com/apache/airflow/pull/67102"><img src="https://img.shields.io/badge/PR-67102-blue" alt="PR Link"></a></td>
</tr>
</table>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb merged PR #66696:
URL: https://github.com/apache/airflow/pull/66696
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3217571654
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
)
+class NullableDatetimeRangeFilter(RangeFilter):
+ """
+ RangeFilter for nullable datetime columns that preserves NULL-as-now semantics.
+
+ Uses explicit OR conditions instead of COALESCE(column, now()) so PostgreSQL
+ can use btree indexes on each branch via BitmapOr plans rather than forcing
+ a full table scan.
+ """
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None:
+ return select
+
+ if self.value.lower_bound_gte:
+ x = self.value.lower_bound_gte
+ select = select.where(or_(self.attribute >= x, and_(self.attribute.is_(None), func.now() >= x)))
Review Comment:
Why do we want `NOW() >= ?` that seems like an odd condition to apply. I would have expected these all to be of the form
```suggestion
select = select.where(or_(self.attribute.is_(None), self.attribute >= x))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(api): replace COALESCE with index-friendly OR conditions in datetime range filters [airflow]
Posted by "hkc-8010 (via GitHub)" <gi...@apache.org>.
hkc-8010 commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3218184315
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -908,17 +937,15 @@ def depends_datetime(
upper_bound_lt: datetime | None = Query(alias=f"{filter_name}_lt", default=None),
) -> RangeFilter:
attr = getattr(model, attribute_name or filter_name)
- if filter_name in ("start_date", "end_date"):
- attr = func.coalesce(attr, func.now())
- return RangeFilter(
- Range(
- lower_bound_gte=lower_bound_gte,
- lower_bound_gt=lower_bound_gt,
- upper_bound_lte=upper_bound_lte,
- upper_bound_lt=upper_bound_lt,
- ),
- attr,
+ range_val = Range(
+ lower_bound_gte=lower_bound_gte,
+ lower_bound_gt=lower_bound_gt,
+ upper_bound_lte=upper_bound_lte,
+ upper_bound_lt=upper_bound_lt,
)
+ if filter_name in ("start_date", "end_date"):
Review Comment:
Good catch, fixed. The check now uses `attribute_name or filter_name` so callers like `datetime_range_filter_factory("dag_run_end_date", DagRun, "end_date")` in `dags.py` correctly return `NullableDatetimeRangeFilter`. Added a test to cover the alias case.
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
)
+class NullableDatetimeRangeFilter(RangeFilter):
+ """
+ RangeFilter for nullable datetime columns that preserves NULL-as-now semantics.
+
+ Uses explicit OR conditions instead of COALESCE(column, now()) so PostgreSQL
+ can use btree indexes on each branch via BitmapOr plans rather than forcing
+ a full table scan.
+ """
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None:
+ return select
Review Comment:
Deliberate — it follows the same pattern as the parent `RangeFilter` class. `value is None` here means the filter block was not requested at all (i.e., no bounds were passed in), not "filter WHERE attribute IS NULL". Since all bounds are typed `datetime | None` at the HTTP layer, the only way `value` is `None` is if the caller constructs the filter object without a `Range`, which doesn't happen via the factory. The IS NULL coverage for running tasks is already embedded in the OR branches below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org