Skip to content

Add serialized Dag version diff engine#69864

Open
ephraimbuddy wants to merge 4 commits into
apache:mainfrom
astronomer:dag-version-diff-core
Open

Add serialized Dag version diff engine#69864
ephraimbuddy wants to merge 4 commits into
apache:mainfrom
astronomer:dag-version-diff-core

Conversation

@ephraimbuddy

@ephraimbuddy ephraimbuddy commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Adds the shared engine that computes an observed-state diff between two stored serialized Dag versions. Dag authors and operators need a reliable way to understand how two stored versions differ without downloading serialized payloads or manually comparing implementation details.

This is the foundation of a three-part stack; the REST API endpoint and the airflow dags versions diff CLI command follow in separate PRs that build on this engine. It intentionally ships with no runtime caller yet — it is fully exercised by unit tests.

What it does

  • build_serialized_dag_diff — pure, deterministic, bounded diff over two serialized payloads. Normalizes task/schedule/dependency/metadata state, converts legacy schema shapes (v1/v2 → v3), keys order-insensitive collections, categorizes each change (task, dependency, schedule, param, asset, callback, deadline, metadata, provenance) and its impact, and emits digests plus optional raw values.
  • get_dag_version_diff — DB-facing wrapper that loads two DagVersions, assembles provenance, and classifies optional source/values data as available, redacted, or unavailable.
  • Malformed legacy payloads and missing historical data degrade to an unavailable result instead of failing the whole request.

Testing

  • 32 unit tests, including a @pytest.mark.db_test class covering get_dag_version_diff end-to-end: observed-state diff, not-found handling, version-number validation, and the values/source status plumbing (available, redacted, unavailable-when-code-missing).
  • prek (ruff, mypy, license, no-new-AirflowException) clean.

No newsfragment: the engine has no user-facing surface on its own; user-facing notes ship with the API and CLI PRs.


Was generative AI tooling used to co-author this PR?
  • Yes — GPT 5.6 & claude code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) & GPT5.6 following the guidelines

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new serialization-layer “observed state” diff engine for comparing two stored serialized Dag payloads, plus a DagVersion model helper and unit tests to exercise both the pure diff and the DB-loading wrapper.

Changes:

  • Introduces build_serialized_dag_diff to compute a deterministic, bounded diff across serialized Dag schema versions (v1/v2 normalized to v3), with optional inclusion of raw values/digests.
  • Adds DagVersion.get_diff(...) to load two DagVersion rows (including provenance and optional source) and return the diff result structure.
  • Adds extensive unit tests for determinism, classification/redaction behavior, truncation, legacy normalization, and DB-backed diff plumbing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
airflow-core/src/airflow/serialization/dag_version_diff.py New pure diff engine: canonicalization, redaction rules, change collection, and change categorization/impact.
airflow-core/src/airflow/models/dag_version.py Adds DagVersion.get_diff wrapper, provenance/source helpers, and a new not-found exception type.
airflow-core/tests/unit/serialization/test_dag_version_diff.py New unit tests covering diff determinism, classification, redaction, legacy normalization, and truncation.
airflow-core/tests/unit/models/test_dag_version.py Adds DB-backed tests for DagVersion.get_diff (values/source status behaviors and missing-version handling).

Comment thread airflow-core/src/airflow/models/dag_version.py
Comment thread airflow-core/src/airflow/models/dag_version.py
Comment thread airflow-core/src/airflow/models/dag_version.py
Dag authors and operators need a reliable way to understand how two stored
Dag versions differ without downloading serialized payloads or manually
comparing implementation details. This adds the shared comparison engine
that later API and CLI surfaces build on.

Historical serialized Dags can use different schema shapes, so comparisons
normalize task, schedule, dependency, and metadata state before calculating
changes. Malformed legacy payloads and missing historical data degrade to
unavailable results instead of failing the whole request.
Users with version access need a useful structural comparison without learning identifiers or values derived from Dag code. The diff contract also needs to remain stable as serializer fields evolve.
Authorization state crosses an internal boundary before API integration, so invalid inputs must fail closed. Consistent not-found semantics also ensure future callers can preserve the required HTTP 404 behavior.
@ephraimbuddy ephraimbuddy force-pushed the dag-version-diff-core branch from 77a23ad to 28351e9 Compare July 14, 2026 16:06
@ephraimbuddy ephraimbuddy marked this pull request as ready for review July 14, 2026 16:11
@ephraimbuddy

Copy link
Copy Markdown
Contributor Author

Extracted from #69818 and reworked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants