uranusjr commented on code in PR #74084:
URL: https://github.com/apache/airflow/pull/74084#discussion_r4204372406


##########
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:
   However not every Python SDK version change would contain changes to the 
schema. It’s weird to bump the schema without change, but if it’s not bumped 
the two go out of sync anyway. The same argument can be made for all schemas 
really (e.g. it would also be useful if the execution api shows which Airflow 
version it’s against), but in reality I think it’s probably more practical to 
keep the date version scheme, and if needed, document the version mapping 
somewhere.



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