You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "amoghrajesh (via GitHub)" <gi...@apache.org> on 2024/11/12 14:48:32 UTC

[PR] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

amoghrajesh opened a new pull request, #43934:
URL: https://github.com/apache/airflow/pull/43934

   <!--
    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/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #43934:
URL: https://github.com/apache/airflow/pull/43934#issuecomment-2478065933

   @pierrejeambrun FYI, I have pushed the changes for all the "resolved" comments. The rest are open for input from 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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844113106


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   tests needs to be simetrical from source code. If the route is in `dags.py`, the test need to be in `test_dags.py`.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842471846


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),

Review Comment:
   Yep, it works fine.
   
   ![image](https://github.com/user-attachments/assets/902275b3-7d54-4b1f-9384-a4cadfa5320f)
   
   ![image](https://github.com/user-attachments/assets/c8274bbc-3c35-492e-ac67-9d3baadf8d9c)
   



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)

Review Comment:
   Tried with Optional as mentioned here https://github.com/apache/airflow/pull/43934#discussion_r1842471846



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844113106


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   tests needs to be simetrical from source code. If the route is in dag_run, the test need to be in `test_dag_runs`.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun merged PR #43934:
URL: https://github.com/apache/airflow/pull/43934


-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844103181


##########
airflow/api_fastapi/common/utils.py:
##########
@@ -0,0 +1,36 @@
+# 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.
+from __future__ import annotations
+
+from datetime import datetime
+
+from fastapi import HTTPException, status
+from pendulum.parsing import ParserError
+
+from airflow.utils import timezone
+
+
+def format_datetime(value: str) -> datetime:
+    """
+    Format datetime objects.
+
+    If it can't be parsed, it returns an HTTP 400 exception.
+    """
+    try:
+        return timezone.parse(value)
+    except (ParserError, TypeError) as err:
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=f"Incorrect datetime argument: {err}")

Review Comment:
   what is the difference with the `_safe_parse_datetime` that is currently in `parameters.py` ? I don't think we should have two of them. 
   
   Also comon



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),

Review Comment:
   You mentionned using `Optional[DateTimeQuery] = None` but the code stills mention `before: str = Query(None)` is that normal?



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844112088


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   Maybe remove the prefix from the router and put that on a `per` route basis in the `assests.py` ? So we can have the route that we want from there ?



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842260722


##########
airflow/api_fastapi/core_api/datamodels/dags.py:
##########
@@ -159,3 +159,18 @@ class DAGTagCollectionResponse(BaseModel):
 
     tags: list[str]
     total_entries: int
+
+
+class QueuedEventResponse(BaseModel):
+    """QueuedEvent serializer for responses.."""

Review Comment:
   ```suggestion
       """Queued Event serializer for responses.."""
   ```



##########
airflow/api_fastapi/core_api/datamodels/dags.py:
##########
@@ -159,3 +159,18 @@ class DAGTagCollectionResponse(BaseModel):
 
     tags: list[str]
     total_entries: int
+
+
+class QueuedEventResponse(BaseModel):
+    """QueuedEvent serializer for responses.."""
+
+    uri: str
+    dag_id: str
+    created_at: datetime
+
+
+class QueuedEventCollectionResponse(BaseModel):
+    """QueuedEventCollection serializer for responses."""

Review Comment:
   ```suggestion
       """Queued Event Collection serializer for responses."""
   ```



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,

Review Comment:
   Latest change of Kaxil's are now putting 401, and 403 to the base router, we don't need to add them on a per `route` basis. (404 and others still need to be added though). 
   https://github.com/apache/airflow/pull/43932



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:

Review Comment:
   We need the common `_generate_queued_event_where_clause` code, or equivalent, because 6 endpoints use that, instead of inlining the code in each endpoints. This will makes things more re-usable and factorized.



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)
+        where_clause.append(AssetDagRunQueue.created_at < before_parsed)
+    query = (
+        select(AssetDagRunQueue, AssetModel.uri)
+        .join(AssetModel, AssetDagRunQueue.asset_id == AssetModel.id)
+        .where(*where_clause)
+    )
+    result = session.execute(query).all()
+    total_entries = len(result)
+    if not result:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, f"Queue event with dag_id: `{dag_id}` was not found")

Review Comment:
   I think you removed the `uri` from the error response message. I think it is important to keep it for the client to understand which event was not found.



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)
+        where_clause.append(AssetDagRunQueue.created_at < before_parsed)
+    query = (
+        select(AssetDagRunQueue, AssetModel.uri)
+        .join(AssetModel, AssetDagRunQueue.asset_id == AssetModel.id)
+        .where(*where_clause)
+    )
+    result = session.execute(query).all()

Review Comment:
   You can also easily add the pagination, add we do for other endpoints, really easy to do with our utility code. This will prevent you from having to do manually:
   ```
   result = session.execute(query).all()
   total_entries = len(result)
   
   ```



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   [This](url) endpoint should be in `assets.py` I think. (same for tests)



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),

Review Comment:
   You can use the `DateTimeQuery` which is the common Safe DateTime parameter. (cf other routes).
   
   Also I think the type is wrong, `str | None` because of the default value.



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)

Review Comment:
   This way you don't need to do that manually.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842454063


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,

Review Comment:
   Yep, done



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842465311


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),

Review Comment:
   I thought of it earlier, the problem with that is that the `_safe_parse_datetime` expects a value which kind of makes the "before" a mandatory field which it is not. I couldn't see an easy way of extending the `_safe_parse_datetime` correctly. It also didnt feel right to do that because we were checking for mandatory field.
   
   Let me try if somethign like: `Optional[DateTimeQuery] = None` works.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844103181


##########
airflow/api_fastapi/common/utils.py:
##########
@@ -0,0 +1,36 @@
+# 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.
+from __future__ import annotations
+
+from datetime import datetime
+
+from fastapi import HTTPException, status
+from pendulum.parsing import ParserError
+
+from airflow.utils import timezone
+
+
+def format_datetime(value: str) -> datetime:
+    """
+    Format datetime objects.
+
+    If it can't be parsed, it returns an HTTP 400 exception.
+    """
+    try:
+        return timezone.parse(value)
+    except (ParserError, TypeError) as err:
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=f"Incorrect datetime argument: {err}")

Review Comment:
   what is the difference with the `_safe_parse_datetime` that is currently in `parameters.py` ? I don't think we should have two of them. 
   
   Also comon/utils is a lot of `generic` placeholder for anything. Maybe `common/datetimes` is more explicit and will keep things cleaner in the future.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842479196


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   Sure, will move it around then



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842479197


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)
+        where_clause.append(AssetDagRunQueue.created_at < before_parsed)
+    query = (
+        select(AssetDagRunQueue, AssetModel.uri)
+        .join(AssetModel, AssetDagRunQueue.asset_id == AssetModel.id)
+        .where(*where_clause)
+    )
+    result = session.execute(query).all()
+    total_entries = len(result)
+    if not result:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, f"Queue event with dag_id: `{dag_id}` was not found")

Review Comment:
   Nope, it was never there. The reason it is not there is because we are getting "ALL" the asset events. So it doesnt make sense to show that. That would make sense if we got one asset event by "uri"



##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   Sure, will move it around then



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842453123


##########
airflow/api_fastapi/core_api/datamodels/dags.py:
##########
@@ -159,3 +159,18 @@ class DAGTagCollectionResponse(BaseModel):
 
     tags: list[str]
     total_entries: int
+
+
+class QueuedEventResponse(BaseModel):
+    """QueuedEvent serializer for responses.."""
+
+    uri: str
+    dag_id: str
+    created_at: datetime
+
+
+class QueuedEventCollectionResponse(BaseModel):
+    """QueuedEventCollection serializer for responses."""

Review Comment:
   Done



##########
airflow/api_fastapi/core_api/datamodels/dags.py:
##########
@@ -159,3 +159,18 @@ class DAGTagCollectionResponse(BaseModel):
 
     tags: list[str]
     total_entries: int
+
+
+class QueuedEventResponse(BaseModel):
+    """QueuedEvent serializer for responses.."""

Review Comment:
   Done



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842476561


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)
+        where_clause.append(AssetDagRunQueue.created_at < before_parsed)
+    query = (
+        select(AssetDagRunQueue, AssetModel.uri)
+        .join(AssetModel, AssetDagRunQueue.asset_id == AssetModel.id)
+        .where(*where_clause)
+    )
+    result = session.execute(query).all()

Review Comment:
   Yeah let me try that as well. The reason I didnt use that mainly was because there's no real pagination for this.
   limit, order_by etc dont exist in this context but I understand that I can set those to None and make do.
   
   Should we consider renaming the `paginated_select` function?



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1843231085


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:

Review Comment:
   Yeah that makes sense, i added a new utils in common to have this, we can reuse it across endpoints imo.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1843316277


##########
tests/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -459,3 +467,76 @@ def test_should_respond_404(self, test_client):
         )
         assert response.status_code == 404
         assert response.json()["detail"] == "The Asset with uri: `s3://bucket/key` was not found"
+
+
+class TestQueuedEventEndpoint:
+    default_time = "2020-06-11T18:00:00+00:00"
+
+    @pytest.fixture(autouse=True)
+    def setup(self) -> None:
+        clear_db_assets()
+
+    def teardown_method(self) -> None:
+        clear_db_assets()
+

Review Comment:
   Good catch, sounds good. I refactored around a bit in tests



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844219293


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   Done.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844231831


##########
airflow/api_fastapi/common/utils.py:
##########
@@ -0,0 +1,36 @@
+# 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.
+from __future__ import annotations
+
+from datetime import datetime
+
+from fastapi import HTTPException, status
+from pendulum.parsing import ParserError
+
+from airflow.utils import timezone
+
+
+def format_datetime(value: str) -> datetime:
+    """
+    Format datetime objects.
+
+    If it can't be parsed, it returns an HTTP 400 exception.
+    """
+    try:
+        return timezone.parse(value)
+    except (ParserError, TypeError) as err:
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=f"Incorrect datetime argument: {err}")

Review Comment:
   REmoved.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844232960


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),

Review Comment:
   Fixed with a new OptionalDateTimeQuery



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1843253079


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)
+        where_clause.append(AssetDagRunQueue.created_at < before_parsed)
+    query = (
+        select(AssetDagRunQueue, AssetModel.uri)
+        .join(AssetModel, AssetDagRunQueue.asset_id == AssetModel.id)
+        .where(*where_clause)
+    )
+    result = session.execute(query).all()

Review Comment:
   cc @pierrejeambrun just adding you for above comment but I have handled it already though paginated_select in the latest commit



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "vatsrahul1001 (via GitHub)" <gi...@apache.org>.
vatsrahul1001 commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1843309719


##########
tests/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -459,3 +467,76 @@ def test_should_respond_404(self, test_client):
         )
         assert response.status_code == 404
         assert response.json()["detail"] == "The Asset with uri: `s3://bucket/key` was not found"
+
+
+class TestQueuedEventEndpoint:
+    default_time = "2020-06-11T18:00:00+00:00"
+
+    @pytest.fixture(autouse=True)
+    def setup(self) -> None:
+        clear_db_assets()
+
+    def teardown_method(self) -> None:
+        clear_db_assets()
+

Review Comment:
   most of [these](https://github.com/apache/airflow/pull/43934/files#diff-5d24f2ed749e37ef9f12eff9a54ad581a0a23df847421f62e9e0289060e931a6R475-R508) fixture and method we already have [here](https://github.com/astronomer/airflow/blob/c593a3f86c400738a743b3739608ed7e95a462dc/tests/api_fastapi/core_api/routes/public/test_assets.py#L122). We can reuse them



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1844316273


##########
airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -42,15 +44,38 @@
     AssetEventCollectionResponse,
     AssetEventResponse,
     AssetResponse,
+    QueuedEventCollectionResponse,
+    QueuedEventResponse,
 )
 from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
-from airflow.models.asset import AssetEvent, AssetModel
+from airflow.models.asset import AssetDagRunQueue, AssetEvent, AssetModel
 
-assets_router = AirflowRouter(tags=["Asset"], prefix="/assets")
+assets_router = AirflowRouter(tags=["Asset"])
+
+
+def _generate_queued_event_where_clause(
+    *,
+    dag_id: str | None = None,
+    uri: str | None = None,
+    before: datetime | None = None,
+) -> list:
+    """Get AssetDagRunQueue where clause."""
+    where_clause = []
+    if dag_id is not None:
+        where_clause.append(AssetDagRunQueue.target_dag_id == dag_id)
+    if uri is not None:
+        where_clause.append(
+            AssetDagRunQueue.asset_id.in_(
+                select(AssetModel.id).where(AssetModel.uri == uri),
+            ),
+        )
+    if before is not None:
+        where_clause.append(AssetDagRunQueue.created_at < before)

Review Comment:
   Yep looks good now!



##########
airflow/api_fastapi/common/parameters.py:
##########
@@ -578,7 +599,8 @@ def depends_float(
 
 
 # Common Safe DateTime
-DateTimeQuery = Annotated[str, AfterValidator(_safe_parse_datetime)]
+DateTimeQuery = Annotated[datetime, AfterValidator(_safe_parse_datetime)]
+OptionalDateTimeQuery = Annotated[Union[datetime, None], AfterValidator(_safe_parse_datetime_optional)]

Review Comment:
   Nice!



##########
airflow/api_fastapi/common/parameters.py:
##########
@@ -373,6 +373,27 @@ def _safe_parse_datetime(date_to_check: str) -> datetime:
     """
     if not date_to_check:
         raise ValueError(f"{date_to_check} cannot be None.")
+    return _safe_parse_datetime_optional(date_to_check)
+
+
+@overload
+def _safe_parse_datetime_optional(date_to_check: str) -> datetime: ...
+
+
+@overload
+def _safe_parse_datetime_optional(date_to_check: None) -> None: ...
+
+
+def _safe_parse_datetime_optional(date_to_check: str | None) -> datetime | None:
+    """
+    Parse datetime and raise error for invalid dates.
+
+    Allow None values.
+
+    :param date_to_check: the string value to be parsed
+    """
+    if date_to_check is None:

Review Comment:
   Looks great, thanks @pierrejeambrun
   Was thinking of doing something like this.



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1842536822


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [

Review Comment:
   @pierrejeambrun I do not think we will be able to do that in fastAPI like we did in connexion becuase I still have to maintain the interface and not change the endpoint to `/public/assets/multi_consumer_dag/assets/queuedEvent`. When i try to register the endpoint to the dags_router from assets.py, I get a circular import:
   
   ```
   test setup failed
   ../../../conftest.py:27: in test_client
       return TestClient(create_app())
   ../../../../../airflow/api_fastapi/app.py:58: in create_app
       init_views(app)
   ../../../../../airflow/api_fastapi/core_api/app.py:49: in init_views
       from airflow.api_fastapi.core_api.routes.public import public_router
   ../../../../../airflow/api_fastapi/core_api/routes/public/__init__.py:24: in <module>
       from airflow.api_fastapi.core_api.routes.public.assets import assets_router
   ../../../../../airflow/api_fastapi/core_api/routes/public/assets.py:48: in <module>
       from airflow.api_fastapi.core_api.routes.public import dags_router
   E   ImportError: cannot import name 'dags_router' from partially initialized module 'airflow.api_fastapi.core_api.routes.public' (most likely due to a circular import) (/Users/amoghdesai/Documents/OSS/airflow/airflow/api_fastapi/core_api/routes/public/__init__.py)
   
   ```



-- 
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] AIP-84: Migrating GET queued asset events for DAG to fastAPI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #43934:
URL: https://github.com/apache/airflow/pull/43934#discussion_r1843237103


##########
airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -303,3 +307,45 @@ def delete_dag(
             status.HTTP_409_CONFLICT, f"Task instances of dag with id: '{dag_id}' are still running"
         )
     return Response(status_code=status.HTTP_204_NO_CONTENT)
+
+
+@dags_router.get(
+    "/{dag_id}/assets/queuedEvent",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_401_UNAUTHORIZED,
+            status.HTTP_403_FORBIDDEN,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_asset_queued_events(
+    dag_id: str,
+    session: Annotated[Session, Depends(get_session)],
+    before: str = Query(None),
+) -> QueuedEventCollectionResponse:
+    """Get queued asset events for a DAG."""
+    where_clause = [AssetDagRunQueue.target_dag_id == dag_id]
+    if before:
+        before_parsed = timezone.parse(before)
+        where_clause.append(AssetDagRunQueue.created_at < before_parsed)
+    query = (
+        select(AssetDagRunQueue, AssetModel.uri)
+        .join(AssetModel, AssetDagRunQueue.asset_id == AssetModel.id)
+        .where(*where_clause)
+    )
+    result = session.execute(query).all()
+    total_entries = len(result)
+    if not result:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, f"Queue event with dag_id: `{dag_id}` was not found")

Review Comment:
   Reference:
   ![image](https://github.com/user-attachments/assets/e17a5079-5151-4e4a-a06b-5a2ebce0fc3a)
   



-- 
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