ephraimbuddy commented on code in PR #74790: URL: https://github.com/apache/airflow/pull/74790#discussion_r4422340518
########## airflow-core/src/airflow/api_fastapi/execution_api/datamodels/dag_parsing.py: ########## @@ -0,0 +1,145 @@ +# 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 typing import Any +from uuid import UUID + +from pydantic import Field, model_validator + +from airflow.api_fastapi.core_api.base import StrictBaseModel +from airflow.api_fastapi.execution_api.datamodels.job import DagParseTokenBody +from airflow.models.dag import TAG_MAX_LEN +from airflow.models.dagwarning import DagWarningTypeValue +from airflow.utils.helpers import validate_key + +MAX_PUBLICATION_BYTES = 16 * 1024 * 1024 +"""Largest request body the Dag parsing endpoints read, measured as the bytes sent.""" + + +class ParseWarning(StrictBaseModel): + """A warning attached to a Dag returned by this import.""" + + dag_id: str = Field(min_length=1, max_length=250) + warning_type: DagWarningTypeValue + message: str + + +class ParseSourceCode(StrictBaseModel): + """Source captured by the importer; null explicitly means unavailable.""" + + source_code: str | None + language: str = Field(min_length=1, max_length=64) + + +class DagParseResultBody(DagParseTokenBody): + """One completed file or container import, including an empty result.""" + + dispatch_sequence: int = Field(ge=1, le=2**53 - 1) + bundle_revision: UUID | None = None + bundle_version: str | None = Field(default=None, max_length=200) + version_data: dict[str, Any] | None = None + parse_duration: float = Field(ge=0, allow_inf_nan=False) + serialized_dags: list[dict[str, Any]] + import_errors: dict[str, str] = Field(default_factory=dict) + warnings: list[ParseWarning] = Field(default_factory=list) + parsed_definitions: list[str] = Field(default_factory=list) + source_codes: dict[str, ParseSourceCode] Review Comment: Done, with a slightly different shape. `source_codes` is a list of unique `{source_code, language}` entries, and `dag_source_indexes `maps each `dag_id` to an index. An index can't dangle the way a hash key can, and an importer can still return different source per Dag. The validator rejects an unmapped Dag, an unused entry, and an index that is out of range or not an integer. -- 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]
