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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to