Copilot commented on code in PR #69864:
URL: https://github.com/apache/airflow/pull/69864#discussion_r3580125690
##########
airflow-core/src/airflow/models/dag_version.py:
##########
@@ -243,6 +251,126 @@ def version(self) -> str:
"""A human-friendly representation of the version."""
return f"{self.dag_id}-{self.version_number}"
+ @classmethod
+ @provide_session
+ def get_diff(
+ cls,
+ dag_id: str,
+ base_version_number: int,
+ target_version_number: int,
+ *,
+ include_values: bool = False,
+ include_source: bool = False,
+ max_changes: int | None = None,
+ source_status: SourceStatus | None = None,
+ values_status: ValuesStatus | None = None,
+ session: Session = NEW_SESSION,
+ ) -> dict[str, Any]:
+ """
+ Compare two versions of a Dag using their currently stored state.
+
+ ``source_status`` is supplied by callers that have an authorization
context. The CLI has
+ operator-level authority and leaves it unset, while API callers
calculate it before this
+ method returns any source content. API callers use ``values_status``
to suppress raw values
+ when the user cannot access Dag code; the structural diff remains
available in redacted form.
+ """
+ from airflow.serialization.dag_version_diff import (
+ DEFAULT_MAX_CHANGES,
+ build_serialized_dag_diff,
+ )
Review Comment:
The function-local import here is presumably to avoid a circular import
(DagVersion → dag_version_diff → DagSerialization → SerializedDAG definition →
DagVersion). Adding a short comment explaining the reason helps future
refactors avoid “fixing” it back to a module import and reintroducing the cycle.
##########
airflow-core/src/airflow/models/dag_version.py:
##########
@@ -243,6 +251,126 @@ def version(self) -> str:
"""A human-friendly representation of the version."""
return f"{self.dag_id}-{self.version_number}"
+ @classmethod
+ @provide_session
+ def get_diff(
+ cls,
+ dag_id: str,
+ base_version_number: int,
+ target_version_number: int,
+ *,
+ include_values: bool = False,
+ include_source: bool = False,
+ max_changes: int | None = None,
+ source_status: SourceStatus | None = None,
+ values_status: ValuesStatus | None = None,
+ session: Session = NEW_SESSION,
+ ) -> dict[str, Any]:
+ """
+ Compare two versions of a Dag using their currently stored state.
+
+ ``source_status`` is supplied by callers that have an authorization
context. The CLI has
+ operator-level authority and leaves it unset, while API callers
calculate it before this
+ method returns any source content. API callers use ``values_status``
to suppress raw values
+ when the user cannot access Dag code; the structural diff remains
available in redacted form.
+ """
+ from airflow.serialization.dag_version_diff import (
+ DEFAULT_MAX_CHANGES,
+ build_serialized_dag_diff,
+ )
+
+ if max_changes is None:
+ max_changes = DEFAULT_MAX_CHANGES
+ if base_version_number < 1 or target_version_number < 1:
+ raise ValueError("Dag version numbers must be positive integers")
+
Review Comment:
`values_status` / `source_status` are runtime strings and currently aren’t
validated. A mistyped/incorrect `values_status` (e.g. "redacted") would be
treated as allowed and could unintentionally enable returning raw values when
`include_values=True`. Validating these parameters keeps the response schema
stable and avoids accidental data exposure caused by caller bugs.
--
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]