pierrejeambrun commented on code in PR #74084: URL: https://github.com/apache/airflow/pull/74084#discussion_r4182602661
########## task-sdk/src/airflow/sdk/importers/yaml_importer/versions/__init__.py: ########## @@ -14,32 +14,25 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +""" +Cadwyn `VersionBundle` for the YAML DAG format, keyed by `$schema` version (a dated URL). + +The `cadwyn` import is deferred so importing this package does not pull in +FastAPI/Starlette. Versions are newest-first. +""" + from __future__ import annotations -from uuid import uuid4 +import functools +from typing import TYPE_CHECKING -import pytest +if TYPE_CHECKING: + from cadwyn import VersionBundle [email protected] -def task_identity_workloads(): - from airflow.executors.workloads import BundleInfo, ExecuteTask, TaskInstanceDTO [email protected] +def get_bundle() -> VersionBundle: + """Build the format's `VersionBundle` lazily (newest-to-oldest).""" + from cadwyn import HeadVersion, Version, VersionBundle Review Comment: Should we add cadwyn to the project dependencies ? (`task-sdk`) Currently it's resolved transitively through `apache-airflow-core` but probably should be declared as direct dependency. ########## task-sdk/src/airflow/sdk/importers/yaml_importer/migrator.py: ########## @@ -0,0 +1,132 @@ +# 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. +""" +`$schema` version resolution and forward migration to the head shape. + +A document pinned to an older `$schema` version is migrated up to the current head shape +*before* validation, by walking the Cadwyn version bundle and applying each `VersionChange`'s +forward request converters (`@convert_request_to_next_version_for(DagDocument)`), oldest to +newest. This mirrors the exec-API / supervisor-schema `SchemaVersionMigrator`, trimmed to the +one direction a document format needs (author's version -> head), with the bundle and its +version list encapsulated in the migrator rather than exposed as module-level helpers. + +With a single published version there is nothing to migrate; the machinery is here so a future +version bump only has to add a `VersionChange` carrying a converter — no parser changes. +""" + +from __future__ import annotations + +import copy +import functools +import re +import warnings +from typing import TYPE_CHECKING, Any + +import attrs + +from airflow.sdk.importers.yaml_importer.models import DagDocument +from airflow.sdk.importers.yaml_importer.versions import get_bundle + +if TYPE_CHECKING: + from cadwyn import VersionBundle + +_SCHEMA_URL = "https://airflow.apache.org/schemas/dag/{date}.json" +_VERSION_RE = re.compile(r"\d{4}-\d{2}-\d{2}") + + +def schema_url(date: str) -> str: + """Build the canonical ``$schema`` URL for a published version *date*.""" + return _SCHEMA_URL.format(date=date) + + +def version_from_schema(schema: str) -> str | None: + """Read the version (``YYYY-MM-DD``) token out of a ``$schema`` URL, ignoring the host.""" + match = _VERSION_RE.search(schema or "") + return match.group(0) if match else None Review Comment: I believe we chose a date format for versions to match cadwyn / bundle versions. This will be released together with the python sdk, I find it less intuitive to have a 'date' version, that needs to be matches against a semver python sdk version to know where it's coming from. Ideally I'd love the public usable version of this to be the sdk version 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
