You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "vikrantkumar-max (via GitHub)" <gi...@apache.org> on 2025/08/19 09:38:52 UTC
[PR] Fix:added none to lastupdatedDate if event is not in queue [airflow]
vikrantkumar-max opened a new pull request, #54652:
URL: https://github.com/apache/airflow/pull/54652
closes: #53817
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
Summary of changes:
Display logic for "X of Y assets":
Y = total assets relevant to the DAG's asset_expression.
X = assets with lastUpdate > latestRunAfter (i.e., new events since last DAG run).
Introduced SQL-based computation of each asset’s "queued" status using a LEFT JOIN + MAX(CASE) approach.
Grouped and normalized the data so:
Non-queued assets have lastUpdate = None.
The internal queued field is removed from the final response payload for clarity.
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #54652:
URL: https://github.com/apache/airflow/pull/54652#discussion_r2344105666
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/assets.py:
##########
@@ -81,5 +87,9 @@ def next_run_assets(
)
]
+ for event in events:
+ if not event.pop('queued', None):
Review Comment:
```suggestion
if not event.pop("queued", None):
```
Fix static checks
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "vikrantkumar-max (via GitHub)" <gi...@apache.org>.
vikrantkumar-max commented on code in PR #54652:
URL: https://github.com/apache/airflow/pull/54652#discussion_r2321723136
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/assets.py:
##########
@@ -81,5 +87,11 @@ def next_run_assets(
)
]
+ for ev in events:
+ queued = ev.get("queued")
+ if not queued:
+ ev["lastUpdate"] = None
+ ev.pop("queued", None)
+
Review Comment:
we need lastUpdate to be set to be None , when there is queued = 0 , because we are filtering on lastUpdate, in FrontEnd , not on Queue, When i tried to put in a single case timestamp becomes string instead of date , then filter will not work as it should be, in FE,
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil merged PR #54652:
URL: https://github.com/apache/airflow/pull/54652
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #54652:
URL: https://github.com/apache/airflow/pull/54652#discussion_r2341215979
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_assets.py:
##########
@@ -74,3 +76,119 @@ def test_should_respond_401(self, unauthenticated_test_client):
def test_should_respond_403(self, unauthorized_test_client):
response = unauthorized_test_client.get("/next_run_assets/upstream")
assert response.status_code == 403
+
+ def test_should_set_last_update_only_for_queued_and_hide_flag(self, test_client, dag_maker, session):
+ with dag_maker(
+ dag_id="two_assets_equal",
+ schedule=[
+ Asset(uri="s3://bucket/A", name="A"),
+ Asset(uri="s3://bucket/B", name="B"),
+ ],
+ serialized=True,
+ ):
+ EmptyOperator(task_id="t")
+
+ dr = dag_maker.create_dagrun()
+ dag_maker.sync_dagbag_to_db()
+
+ assets = {
+ a.uri: a
+ for a in session.query(AssetModel).filter(AssetModel.uri.in_(["s3://bucket/A", "s3://bucket/B"]))
+ }
+ # Queue and add an event only for A
+ session.add(AssetDagRunQueue(asset_id=assets["s3://bucket/A"].id, target_dag_id="two_assets_equal"))
+ session.add(
+ AssetEvent(asset_id=assets["s3://bucket/A"].id, timestamp=dr.logical_date or pendulum.now())
+ )
+ session.commit()
+
+ response = test_client.get("/next_run_assets/two_assets_equal")
+ assert response.status_code == 200
+ assert response.json() == {
+ "asset_expression": {
+ "all": [
+ {
+ "asset": {
+ "uri": "s3://bucket/A",
+ "name": "A",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ {
+ "asset": {
+ "uri": "s3://bucket/B",
+ "name": "B",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ ]
+ },
+ # events are ordered by uri
+ "events": [
+ {"id": mock.ANY, "uri": "s3://bucket/A", "name": "A", "lastUpdate": mock.ANY},
+ {"id": mock.ANY, "uri": "s3://bucket/B", "name": "B", "lastUpdate": None},
+ ],
+ }
+
+ def test_two_assets_only_one_queued_last_update_norm(self, test_client, dag_maker, session):
Review Comment:
What's the purpose of this test case? Could we merge this one into the one above?
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/assets.py:
##########
@@ -81,5 +87,11 @@ def next_run_assets(
)
]
+ for ev in events:
+ queued = ev.get("queued")
+ if not queued:
+ ev["lastUpdate"] = None
+ ev.pop("queued", None)
Review Comment:
```suggestion
for event in events:
if not event.pop("queued", None):
event["lastUpdate"] = None
```
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #54652:
URL: https://github.com/apache/airflow/pull/54652#discussion_r2315774611
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_assets.py:
##########
@@ -74,3 +77,128 @@ def test_should_respond_401(self, unauthenticated_test_client):
def test_should_respond_403(self, unauthorized_test_client):
response = unauthorized_test_client.get("/next_run_assets/upstream")
assert response.status_code == 403
+
+ def test_should_set_last_update_only_for_queued_and_hide_flag(self, test_client, dag_maker):
+ with dag_maker(
Review Comment:
same for dag_mager, use as fixture.
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on PR #54652:
URL: https://github.com/apache/airflow/pull/54652#issuecomment-3312232115
Static check failed
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #54652:
URL: https://github.com/apache/airflow/pull/54652#issuecomment-3264728617
static tests are failing
https://github.com/apache/airflow/actions/runs/17540148126/job/49810680060?pr=54652#step:6:194
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #54652:
URL: https://github.com/apache/airflow/pull/54652#discussion_r2362936298
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_assets.py:
##########
@@ -74,3 +76,85 @@ def test_should_respond_401(self, unauthenticated_test_client):
def test_should_respond_403(self, unauthorized_test_client):
response = unauthorized_test_client.get("/next_run_assets/upstream")
assert response.status_code == 403
+
+ def test_should_set_last_update_only_for_queued_and_hide_flag(self, test_client, dag_maker, session):
+ with dag_maker(
+ dag_id="two_assets_equal",
+ schedule=[
+ Asset(uri="s3://bucket/A", name="A"),
+ Asset(uri="s3://bucket/B", name="B"),
+ ],
+ serialized=True,
+ ):
+ EmptyOperator(task_id="t")
+
+ dr = dag_maker.create_dagrun()
+ dag_maker.sync_dagbag_to_db()
+
+ assets = {
+ a.uri: a
+ for a in session.query(AssetModel).filter(AssetModel.uri.in_(["s3://bucket/A", "s3://bucket/B"]))
+ }
+ # Queue and add an event only for A
+ session.add(AssetDagRunQueue(asset_id=assets["s3://bucket/A"].id, target_dag_id="two_assets_equal"))
+ session.add(
+ AssetEvent(asset_id=assets["s3://bucket/A"].id, timestamp=dr.logical_date or pendulum.now())
+ )
+ session.commit()
+
+ response = test_client.get("/next_run_assets/two_assets_equal")
+ assert response.status_code == 200
+ assert response.json() == {
+ "asset_expression": {
+ "all": [
+ {
+ "asset": {
+ "uri": "s3://bucket/A",
+ "name": "A",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ {
+ "asset": {
+ "uri": "s3://bucket/B",
+ "name": "B",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ ]
+ },
+ # events are ordered by uri
+ "events": [
+ {"id": mock.ANY, "uri": "s3://bucket/A", "name": "A", "lastUpdate": mock.ANY},
+ {"id": mock.ANY, "uri": "s3://bucket/B", "name": "B", "lastUpdate": None},
+ ],
+ }
+
+
Review Comment:
```suggestion
```
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #54652:
URL: https://github.com/apache/airflow/pull/54652#discussion_r2315766793
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/assets.py:
##########
@@ -81,5 +87,11 @@ def next_run_assets(
)
]
+ for ev in events:
+ queued = ev.get("queued")
+ if not queued:
+ ev["lastUpdate"] = None
+ ev.pop("queued", None)
+
Review Comment:
I think this could be incorporated directly above in the query when we construct the `lastUpdate` column.
This will avoid having to iterate over the events again and poping `queued`.
We just need to combine those two:
```
func.max(AssetEvent.timestamp).label("lastUpdate"),
func.max(
case(
(AssetDagRunQueue.asset_id.is_not(None), 1),
else_=0,
)
).label("queued"),
```
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_assets.py:
##########
@@ -74,3 +77,128 @@ def test_should_respond_401(self, unauthenticated_test_client):
def test_should_respond_403(self, unauthorized_test_client):
response = unauthorized_test_client.get("/next_run_assets/upstream")
assert response.status_code == 403
+
+ def test_should_set_last_update_only_for_queued_and_hide_flag(self, test_client, dag_maker):
+ with dag_maker(
+ dag_id="two_assets_equal",
+ schedule=[
+ Asset(uri="s3://bucket/A", name="A"),
+ Asset(uri="s3://bucket/B", name="B"),
+ ],
+ serialized=True,
+ ):
+ EmptyOperator(task_id="t")
+
+ dr = dag_maker.create_dagrun()
+ dag_maker.sync_dagbag_to_db()
+
+ with create_session() as session:
+ assets = {
+ a.uri: a
+ for a in session.query(AssetModel).filter(
+ AssetModel.uri.in_(["s3://bucket/A", "s3://bucket/B"])
+ )
+ }
+ # Queue and add an event only for A
+ session.add(
+ AssetDagRunQueue(asset_id=assets["s3://bucket/A"].id, target_dag_id="two_assets_equal")
+ )
+ session.add(
+ AssetEvent(asset_id=assets["s3://bucket/A"].id, timestamp=dr.logical_date or pendulum.now())
+ )
+ session.commit()
+
+ response = test_client.get("/next_run_assets/two_assets_equal")
+ assert response.status_code == 200
+ assert response.json() == {
+ "asset_expression": {
+ "all": [
+ {
+ "asset": {
+ "uri": "s3://bucket/A",
+ "name": "A",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ {
+ "asset": {
+ "uri": "s3://bucket/B",
+ "name": "B",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ ]
+ },
+ # events are ordered by uri
+ "events": [
+ {"id": mock.ANY, "uri": "s3://bucket/A", "name": "A", "lastUpdate": mock.ANY},
+ {"id": mock.ANY, "uri": "s3://bucket/B", "name": "B", "lastUpdate": None},
+ ],
+ }
+
+ def test_two_assets_only_one_queued_last_update_norm(self, test_client, dag_maker):
Review Comment:
you can use the `session` fixture instead.
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_assets.py:
##########
@@ -74,3 +77,128 @@ def test_should_respond_401(self, unauthenticated_test_client):
def test_should_respond_403(self, unauthorized_test_client):
response = unauthorized_test_client.get("/next_run_assets/upstream")
assert response.status_code == 403
+
+ def test_should_set_last_update_only_for_queued_and_hide_flag(self, test_client, dag_maker):
+ with dag_maker(
+ dag_id="two_assets_equal",
+ schedule=[
+ Asset(uri="s3://bucket/A", name="A"),
+ Asset(uri="s3://bucket/B", name="B"),
+ ],
+ serialized=True,
+ ):
+ EmptyOperator(task_id="t")
+
+ dr = dag_maker.create_dagrun()
+ dag_maker.sync_dagbag_to_db()
+
+ with create_session() as session:
+ assets = {
+ a.uri: a
+ for a in session.query(AssetModel).filter(
+ AssetModel.uri.in_(["s3://bucket/A", "s3://bucket/B"])
+ )
+ }
+ # Queue and add an event only for A
+ session.add(
+ AssetDagRunQueue(asset_id=assets["s3://bucket/A"].id, target_dag_id="two_assets_equal")
+ )
+ session.add(
+ AssetEvent(asset_id=assets["s3://bucket/A"].id, timestamp=dr.logical_date or pendulum.now())
+ )
+ session.commit()
+
+ response = test_client.get("/next_run_assets/two_assets_equal")
+ assert response.status_code == 200
+ assert response.json() == {
+ "asset_expression": {
+ "all": [
+ {
+ "asset": {
+ "uri": "s3://bucket/A",
+ "name": "A",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ {
+ "asset": {
+ "uri": "s3://bucket/B",
+ "name": "B",
+ "group": "asset",
+ "id": mock.ANY,
+ }
+ },
+ ]
+ },
+ # events are ordered by uri
+ "events": [
+ {"id": mock.ANY, "uri": "s3://bucket/A", "name": "A", "lastUpdate": mock.ANY},
+ {"id": mock.ANY, "uri": "s3://bucket/B", "name": "B", "lastUpdate": None},
+ ],
+ }
+
+ def test_two_assets_only_one_queued_last_update_norm(self, test_client, dag_maker):
+ with dag_maker(
+ dag_id="two_assets",
+ schedule=[
+ Asset(uri="s3://bucket/A", name="A"),
+ Asset(uri="s3://bucket/B", name="B"),
+ ],
+ serialized=True,
+ ):
+ EmptyOperator(task_id="t")
+
+ dr = dag_maker.create_dagrun()
+ dag_maker.sync_dagbag_to_db()
+
+ with create_session() as session:
+ assets = {
+ a.uri: a
+ for a in session.query(AssetModel).filter(
+ AssetModel.uri.in_(["s3://bucket/A", "s3://bucket/B"])
+ )
+ }
+ session.add(AssetDagRunQueue(asset_id=assets["s3://bucket/A"].id, target_dag_id="two_assets"))
+ session.add(
+ AssetEvent(asset_id=assets["s3://bucket/A"].id, timestamp=dr.logical_date or pendulum.now())
+ )
+ session.commit()
+
+ resp = test_client.get("/next_run_assets/two_assets")
+ assert resp.status_code == 200
+ events = resp.json()["events"]
+ # ordered by uri => A then B
+ assert events[0]["uri"] == "s3://bucket/A"
+ assert events[0]["lastUpdate"] is not None
+ assert "queued" not in events[0]
+ assert events[1]["uri"] == "s3://bucket/B"
+ assert events[1]["lastUpdate"] is None
+ assert "queued" not in events[1]
+
+ def test_last_update_respects_latest_run_filter(self, test_client, dag_maker):
+ with dag_maker(
+ dag_id="filter_run",
+ schedule=[Asset(uri="s3://bucket/F", name="F")],
+ serialized=True,
+ ):
+ EmptyOperator(task_id="t")
+
+ dr = dag_maker.create_dagrun()
+ dag_maker.sync_dagbag_to_db()
+
+ with create_session() as session:
Review Comment:
session fixture.
--
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:added none to lastupdated Date if event is not in queue [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #54652:
URL: https://github.com/apache/airflow/pull/54652#issuecomment-3312251607
Should pass the static checks now
--
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