amoghrajesh commented on code in PR #43874: URL: https://github.com/apache/airflow/pull/43874#discussion_r1839639345
########## airflow/api_fastapi/core_api/datamodels/assets.py: ########## @@ -0,0 +1,103 @@ +# 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 pydantic import BaseModel, Field + + +class DagScheduleAssetReference(BaseModel): + """Serializable version of the DagScheduleAssetReference ORM SqlAlchemyModel.""" + + dag_id: str + created_at: datetime + updated_at: datetime + + +class TaskOutletAssetReference(BaseModel): + """Serializable version of the TaskOutletAssetReference ORM SqlAlchemyModel.""" + + dag_id: str + task_id: str + created_at: datetime + updated_at: datetime + + +class AssetAliasSchema(BaseModel): + """Serializable version of the AssetAliasSchema ORM SqlAlchemyModel.""" + + id: int + name: str + + +class AssetResponse(BaseModel): + """Asset serializer for responses.""" + + id: int + uri: str + extra: dict | None = None + created_at: datetime + updated_at: datetime + consuming_dags: list[DagScheduleAssetReference] + producing_tasks: list[TaskOutletAssetReference] + aliases: list[AssetAliasSchema] + + +class AssetCollectionResponse(BaseModel): + """Asset collection response.""" + + assets: list[AssetResponse] + total_entries: int + + +class DagRunAssetReference(BaseModel): + """Serializable version of the DagRunAssetReference ORM SqlAlchemyModel.""" + + run_id: str + dag_id: str + execution_date: datetime = Field(alias="logical_date") + start_date: datetime + end_date: datetime | None = None + state: str + data_interval_start: datetime + data_interval_end: datetime + + +class AssetEventResponse(BaseModel): + """Asset event serializer for responses.""" + + id: int + asset_id: int + # piggyback on the fix for https://github.com/apache/airflow/issues/43845 for asset_uri + # meanwhile, unblock by adding uri below Review Comment: Made the change and it works as expected ########## airflow/api_fastapi/core_api/datamodels/assets.py: ########## @@ -0,0 +1,103 @@ +# 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 pydantic import BaseModel, Field + + +class DagScheduleAssetReference(BaseModel): + """Serializable version of the DagScheduleAssetReference ORM SqlAlchemyModel.""" + + dag_id: str + created_at: datetime + updated_at: datetime + + +class TaskOutletAssetReference(BaseModel): + """Serializable version of the TaskOutletAssetReference ORM SqlAlchemyModel.""" + + dag_id: str + task_id: str + created_at: datetime + updated_at: datetime + + +class AssetAliasSchema(BaseModel): + """Serializable version of the AssetAliasSchema ORM SqlAlchemyModel.""" + + id: int + name: str + + +class AssetResponse(BaseModel): + """Asset serializer for responses.""" + + id: int + uri: str + extra: dict | None = None + created_at: datetime + updated_at: datetime + consuming_dags: list[DagScheduleAssetReference] + producing_tasks: list[TaskOutletAssetReference] + aliases: list[AssetAliasSchema] + + +class AssetCollectionResponse(BaseModel): + """Asset collection response.""" + + assets: list[AssetResponse] + total_entries: int + + +class DagRunAssetReference(BaseModel): + """Serializable version of the DagRunAssetReference ORM SqlAlchemyModel.""" + + run_id: str + dag_id: str + execution_date: datetime = Field(alias="logical_date") + start_date: datetime + end_date: datetime | None = None + state: str + data_interval_start: datetime + data_interval_end: datetime + + +class AssetEventResponse(BaseModel): + """Asset event serializer for responses.""" + + id: int + asset_id: int + # piggyback on the fix for https://github.com/apache/airflow/issues/43845 for asset_uri + # meanwhile, unblock by adding uri below Review Comment: Response: ``` { "asset_events": [ { "id": 2, "asset_id": 1, "asset_uri": "wasb://somepath/", "extra": {}, "source_task_id": "producer2", "source_dag_id": "producer2_dag", "source_run_id": "manual__2024-11-12T12:40:53.566380+00:00", "source_map_index": -1, "created_dagruns": [ { "run_id": "asset_triggered__2024-11-12T12:40:54.754807+00:00", "dag_id": "multi_consumer_dag", "logical_date": "2024-11-12T12:40:54.754807Z", "start_date": "2024-11-12T12:40:54.903281Z", "end_date": "2024-11-12T12:40:55.936560Z", "state": "success", "data_interval_start": "2024-11-12T12:40:51.405849Z", "data_interval_end": "2024-11-12T12:40:53.566380Z" }, { "run_id": "asset_triggered__2024-11-12T12:40:54.754809+00:00", "dag_id": "consumer2_dag", "logical_date": "2024-11-12T12:40:54.754809Z", "start_date": "2024-11-12T12:40:54.903329Z", "end_date": "2024-11-12T12:40:55.939573Z", "state": "success", "data_interval_start": "2024-11-12T12:40:53.566380Z", "data_interval_end": "2024-11-12T12:40:53.566380Z" } ], "timestamp": "2024-11-12T12:40:54.753857Z" } ], "total_entries": 1 } ``` -- 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]
