Lee-W commented on code in PR #74583:
URL: https://github.com/apache/airflow/pull/74583#discussion_r4692182500
##########
airflow-core/src/airflow/assets/manager.py:
##########
@@ -762,6 +783,40 @@ def _get_or_create_apdr(
target_dag.dag_id,
exc_info=True,
)
+
+ if (
+ refire_policy is not None
+ and latest_apdr is not None
+ and latest_apdr.created_dag_run_id is not None
+ ):
+ prior_logs = session.scalars(
+ select(PartitionedAssetKeyLog).where(
+ PartitionedAssetKeyLog.asset_partition_dag_run_id ==
latest_apdr.id,
+ PartitionedAssetKeyLog.asset_id != asset_id,
Review Comment:
The `asset_id !=` condition drops every earlier key log of the arriving
asset, not just the one the late event replaces. With a rollup mapper (several
source keys per asset) one late source key would leave the new APDR holding
only that key, so it may never become satisfiable. Could the seed exclude only
the superseded `(asset_id, source_key)` and copy the rest, with a test that has
an earlier log for the arriving asset and one with multiple source keys?
##########
airflow-core/tests/unit/assets/test_manager.py:
##########
@@ -880,6 +881,131 @@ def
test_assigning_created_dag_run_id_clears_pending_partition_key(self):
assert apdr.pending_partition_key is None
+ @pytest.mark.usefixtures("testing_dag_bundle")
+ def test_get_or_create_apdr_refire_seeds_sibling_logs(self, session):
Review Comment:
the fired APDR here only has a key log for the sibling asset, so the
asset_id != condition in the seed query is never exercised. Could it also get
an earlier log for the arriving asset with an assertion on how it is handled,
plus a newrun test that checks the copied content end to end, and a scheduler
test that a new event for the same key after a rerun creates a new pending APDR?
##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2695,6 +2695,45 @@ def _create_dagruns_for_partitioned_asset_dags(self,
session: Session) -> set[st
dag_id=apdr.target_dag_id,
carried_partition_date=apdr.partition_date,
)
+ # Refire Semantics A ("rerun"): clear + re-queue the existing
DagRun for this
+ # (dag, partition_key) instead of creating a new one, so a
late/corrected
+ # event reprocesses in the same DagRun (attempts increment).
+ if getattr(timetable, "refire_policy", None) == "rerun":
+ existing_run = session.scalar(
Review Comment:
This lookup picks the newest DagRun by `(dag_id, partition_key)` with no
`run_type` or link to the APDR chain, so a manual or backfill run on the same
partition key could be the one that gets cleared and re-queued.
Could the run be resolved from the earlier APDR’s `created_dag_run_id` for
the same `(target_dag_id, partition_key)`, and could a test put a manual run on
the same key and assert its clear_number stays 0 while the asset-triggered run
is re-run?
##########
airflow-core/src/airflow/assets/manager.py:
##########
@@ -687,7 +691,24 @@ def _get_or_create_apdr(
``rollup_fingerprint`` is the serialized mapper / window definition
for all partitioned
assets in the timetable at creation time; the scheduler discards APDRs
whose stamp no
longer matches the current timetable's fingerprint (mapper / window
may have changed).
+
+ When ``refire_policy`` is set and the latest APDR has already fired,
sibling asset-key
+ logs are copied to the new APDR so a corrected event can satisfy the
asset condition again.
"""
+ latest_apdr = None
+ if refire_policy is not None:
+ latest_apdr = session.scalar(
+ select(AssetPartitionDagRun)
+ .where(
+ AssetPartitionDagRun.partition_key == target_key,
+ AssetPartitionDagRun.target_dag_id == target_dag.dag_id,
+ )
+ .order_by(AssetPartitionDagRun.id.desc())
+ .limit(1)
+ )
+ if latest_apdr is not None and latest_apdr.created_dag_run_id is
not None and asset_id is None:
Review Comment:
When will `asset_id` be None?
##########
airflow-core/docs/authoring-and-scheduling/assets.rst:
##########
@@ -730,6 +730,37 @@ including ``partition_key`` in the request body):
"partition_key": "us|2026-03-10T09:00:00"
}'
+Handling late or corrected events
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+By default, once a partition has triggered a Dag run, a later asset event for
+the same partition key does not affect that run — it starts a new, independent
Review Comment:
It says a late event starts a new, independent Dag run by default, the
`refire_policy=None` bullet says each satisfied partition triggers exactly one
Dag run, and the "rerun" bullet calls the leftover a "duplicate, unsatisfiable
Dag run" although an unsatisfiable APDR never creates a run.
Could the section state what the default does for single-asset and
multi-asset conditions, how `newrun` differs from it, and what happens to a run
that is still running?
##########
task-sdk/tests/task_sdk/definitions/timetables/test_assets.py:
##########
@@ -50,6 +50,23 @@ def
test_partitioned_timetable_preserves_positional_mapper_arguments(batch_asset
assert timetable.batch_asset_events is batch_asset_events
+def test_partitioned_timetable_refire_policy_defaults_to_none():
+ assert PartitionedAssetTimetable(assets=Asset("test")).refire_policy is
None
+
+
[email protected]("refire_policy", ["rerun", "newrun"])
+def test_partitioned_timetable_refire_policy_is_settable(refire_policy):
+ timetable = PartitionedAssetTimetable(assets=Asset("test"),
refire_policy=refire_policy)
+ assert timetable.refire_policy == refire_policy
+
+
[email protected]("refire_policy", ["Rerun", "rerun ", "always", ""])
+def test_partitioned_timetable_rejects_invalid_refire_policy(refire_policy):
Review Comment:
only the rejection path is covered, so shrinking `_VALID_REFIRE_POLICIES` to
`(None,)` would leave this file green and wrongly rejecting "rerun" or "newrun"
would go unnoticed. Could you add accepting cases for `None, "rerun" and
"newrun"` through `validate()`, and one through `Dag.validate()`
(test_compound_asset_condition_requires_batching in the same file is a
precedent)?
--
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]