Skip to content

Fix double-serialization issue by unwrapping serialized kwargs in encode_trigger#64626

Merged
kaxil merged 3 commits intoapache:mainfrom
jason810496:fix/core-serde/double-encode-trigger
Apr 2, 2026
Merged

Fix double-serialization issue by unwrapping serialized kwargs in encode_trigger#64626
kaxil merged 3 commits intoapache:mainfrom
jason810496:fix/core-serde/double-encode-trigger

Conversation

@jason810496
Copy link
Copy Markdown
Member

@jason810496 jason810496 commented Apr 2, 2026

What

Inspired from #64625 but moved the logic into encoder instead of spreading in dag_processing/collection

Verification

  • The trigger will show up and will not disappear once unpause from Airflow UI
    • The trigger show up in Triggerer logging
    • Also directly select in DB to verify PGPASSWORD='airflow' psql -h postgres -U postgres -d airflow -c "SELECT * FROM trigger;"
  • The External-Event Driven Dag with Kafka Queue described in Deserialization error for External-Event Driven Dag #64613 works
    • The Dag behave same in 3.1.8
Screenshot 2026-04-02 at 9 23 51 PM Screenshot 2026-04-02 at 9 24 09 PM

Co-authored-by: Rahul Vats 43964496+vatsrahul1001@users.noreply.github.com

@jason810496
Copy link
Copy Markdown
Member Author

I'm working on the unit tests right now.

@jason810496 jason810496 requested a review from XD-DENG as a code owner April 2, 2026 15:15
@jason810496 jason810496 force-pushed the fix/core-serde/double-encode-trigger branch from 3de7e33 to 0084161 Compare April 2, 2026 15:56
@vatsrahul1001 vatsrahul1001 requested a review from kaxil April 2, 2026 17:49
@vatsrahul1001 vatsrahul1001 added the backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch label Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a trigger double-serialization problem during DAG (re-)serialization that caused asset-watcher trigger hashes to change between the “DAG-parsed” and “DB-loaded” paths (leading to repeated trigger deletion/recreation and disappearing triggers).

Changes:

  • Update encode_trigger() to unwrap already-serialized kwarg values before re-serializing, preventing double-wrapping.
  • Add unit + DB tests to validate encode_trigger() idempotency and trigger-hash consistency through DB round-trips.
  • Adjust Trigger model imports around Callback usage.

Reviewed changes

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

File Description
airflow-core/src/airflow/serialization/encoders.py Adds “unwrap then re-serialize” logic to prevent double-serialization of trigger kwargs.
airflow-core/tests/unit/serialization/test_encoders.py New tests for encode_trigger() idempotency and DAG-vs-DB hash consistency.
airflow-core/tests/unit/dag_processing/test_collection.py Adds regression tests for asset trigger reference hash consistency and idempotency.
airflow-core/src/airflow/models/trigger.py Moves Callback import usage into methods (query paths involving callbacks).

Comment on lines +24 to +30
from airflow.serialization.encoders import encode_trigger
from airflow.serialization.enums import DagAttributeTypes as DAT, Encoding
from airflow.triggers.base import BaseEventTrigger

pytest.importorskip("airflow.providers.apache.kafka")
from airflow.providers.apache.kafka.triggers.await_message import AwaitMessageTrigger

Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

pytest.importorskip("airflow.providers.apache.kafka") at module import time will skip this entire test module when the Kafka provider isn't installed, including the FileDeleteTrigger coverage (which should be provider-independent) and the DB hash consistency checks.

Consider moving the importorskip/Kafka import into only the Kafka-specific parametrized cases (e.g., conditionally add Kafka params, or mark those params with skip) so the non-Kafka assertions still run in minimal test environments.

Copilot uses AI. Check for mistakes.
Comment on lines +189 to +194
recreate trigger rows on every heartbeat.
"""
from airflow.models.trigger import Trigger
from airflow.serialization.encoders import encode_trigger
from airflow.triggers.base import BaseEventTrigger

Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

These new inline imports are unnecessary here since the file already has module-level imports, and they make it harder to see dependencies/trigger lint rules. Please move Trigger, encode_trigger, and BaseEventTrigger imports to the top of the module (or otherwise document why they must remain local).

Copilot uses AI. Check for mistakes.
Comment on lines +236 to +241
"""Calling add_asset_trigger_references twice with the same trigger
must not create duplicate rows.
"""
from airflow.models.trigger import Trigger

trigger = FileDeleteTrigger(filepath="/tmp/test.txt", poke_interval=5.0)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

New inline import in the test body; since this module already imports most dependencies at the top, please move Trigger to module scope for consistency/readability (unless there’s a specific reason to keep it local).

Copilot uses AI. Check for mistakes.
@kaxil kaxil merged commit d292e0e into apache:main Apr 2, 2026
86 checks passed
@github-actions github-actions bot added this to the Airflow 3.2.1 milestone Apr 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.2.1 based on: backport label targeting v3-2-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

@kaxil
Copy link
Copy Markdown
Member

kaxil commented Apr 2, 2026

Merged to unblock rc2 but we should follow-up with minor fixes identified about imports

github-actions bot pushed a commit that referenced this pull request Apr 2, 2026
…wargs in `encode_trigger` (#64626)

(cherry picked from commit d292e0e)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Backport successfully created: v3-2-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-2-test PR Link

github-actions bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Apr 2, 2026
…wargs in `encode_trigger` (apache#64626)

(cherry picked from commit d292e0e)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request Apr 2, 2026
…wargs in `encode_trigger` (#64626) (#64642)

(cherry picked from commit d292e0e)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request Apr 8, 2026
…wargs in `encode_trigger` (#64626) (#64642)

(cherry picked from commit d292e0e)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:DAG-processing backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trigger and Watcher it not running for External-Event Driven Dag

4 participants