Skip to content

Add partition_key to Metadata so yield matches outlet_events - #71999

Open
Vamsi-klu wants to merge 6 commits into
apache:mainfrom
Vamsi-klu:pr3/69117-metadata-partition-parity
Open

Add partition_key to Metadata so yield matches outlet_events#71999
Vamsi-klu wants to merge 6 commits into
apache:mainfrom
Vamsi-klu:pr3/69117-metadata-partition-parity

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

What is the change?

Metadata gains an optional partition_keys field that takes one key or a list, the same values outlet_events[asset].add_partitions accepts. The sync and async callback runners call add_partitions when it is set, so yielding Metadata records partitions exactly like the accessor API.

Why did I do it?

closes: #69117

The docs said the two APIs were equivalent. For extra they are; for partitions they were not. Setting extra never selects a partition, so a partitioned consumer got no AssetPartitionDagRun and users had no yield-based way to attach a key.

How did I do it?

partition_keys: str | list[str] | None = None is the last field, so existing positional Metadata(asset, extra) calls keep working. After merging extra, the runner calls add_partitions. Invalid keys raise and fail the task before any event is emitted. Keys land on the concrete asset accessor only; alias-resolved events keep the producing Dag run's key. I updated the assets docs with the equivalence and the partitioned-consumer rules.

What's the impact?

Task authors can attach partition keys from a yield. Extra-only emits to a partitioned consumer still log a missing-key warning and create no run. No scheduler change.

What's the test plan?

New test_callback_runner.py covers merging, list keys, alias interaction, and invalid keys for both runners. Parity tests in test_scheduler_job.py run both APIs and compare events, AssetPartitionDagRun rows, and consumer runs. test_taskinstance.py adds mapped injection and invalid-key tests; test_task_runner.py pins serialization.


Was generative AI tooling used to co-author this PR?
  • Yes (Grok 4.6)

Generated-by: Grok 4.6 following the guidelines

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

cc @dstandish@jroachgolf84@ashb@kaxil@Lee-W@uranusjr Metadata.partition_key so yield matches outlet_events.add_partitions.


Drafted-by: Cursor Grok 4.6; reviewed by @Vamsi-klu before posting

@uranusjr
uranusjr requested a review from Lee-WAugust 23, 2026 07:51
Vamsi-kluand others added 4 commits August 24, 2026 00:18
Docs treated yield Metadata and outlet_events as the same API. Extra
already merged onto the same accessor, but partitioned consumers need
an explicit key and extra was never a substitute.
closes: apache#69117
The upgrade note pointed at an unmerged batching PR, alias docs did not
say where partition_key is recorded, and one ADRQ assertion counted the
whole table.
The check rejects issue-numbered fragments so the changelog entry
links to the change that actually merged.
Co-authored-by: Cursor <cursoragent@cursor.com>
The check rejects a fragment named for an older number so the
changelog entry links to the change that actually merged.
Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor
cursorBotforce-pushed the pr3/69117-metadata-partition-parity branch from eba6c0d to b192b4aCompareAugust 24, 2026 00:18
Comment threadairflow-core/newsfragments/71999.bugfix.rst Outdated
Comment threadtask-sdk/src/airflow/sdk/definitions/asset/metadata.py Outdated
The two emit APIs should take the same keys argument. A single-key field still forced one yield per partition, and the changelog called that a bug when it is just the missing side of the API.
@Vamsi-klu
Vamsi-klu requested a review from Lee-WAugust 24, 2026 16:08
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Schedulerincluding HA (high availability) schedulerarea:task-sdkkind:documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistency between yielding Metadata and outlet_events extras for partitioned Assets

3 participants

@Vamsi-klu@Lee-W@cursoragent