Fix DAG deserialization failure with non-default weight_rule#55906
Merged
Conversation
ashb
reviewed
Sep 19, 2025
ashb
approved these changes
Sep 19, 2025
ashb
left a comment
Member
There was a problem hiding this comment.
Tests not happy now, but lgtm otherwise
612bb92 to
41a0719
Compare
Resolves an issue where DAGs using non default value like `weight_rule='absolute'` would fail during
deserialization with `'Unknown priority strategy'` error. The problem occurred
when the scheduler attempted to deserialize tasks that had already been
converted to `PriorityWeightStrategy` instances.
The `validate_and_load_priority_weight_strategy` function now properly handles
cases where a `PriorityWeightStrategy` instance is passed, returning it directly
instead of attempting to re-validate it.
This fix ensures that all weight rule options (`downstream`, `upstream`, `absolute`)
work correctly in the complete DAG processing pipeline including serialization,
storage, and deserialization.
To Reproduce the bug, run the following dag or just run the added unit test without code changes:
```py
from airflow import DAG
from airflow.sdk import task
from airflow.task.weight_rule import WeightRule
with DAG("xcom_backend_dag"):
@task()
def xcom_producer():
return "my_value"
@task(weight_rule=WeightRule.ABSOLUTE)
def xcom_consumer(value):
assert value == "my_value"
xcom_consumer(xcom_producer())
```
which will then fail, when you try to trigger the dag from UI.
Fix DAG deserialization failure with weight_rule='absolute'
Resolves an issue where DAGs using weight_rule='absolute' would fail during
deserialization with 'Unknown priority strategy' error. The problem occurred
when the SerializedBaseOperator.weight_rule property was re-validating
already-instantiated PriorityWeightStrategy instances.
During deserialization, decode_priority_weight_strategy() creates strategy
instances and stores them in _weight_rule, but the weight_rule property
was calling validate_and_load_priority_weight_strategy() which expected
a string or class, not an instance.
Fixed by checking if _weight_rule is already a PriorityWeightStrategy
instance in the property getter and returning it directly. User input
still goes through proper validation.
This targeted fix resolves the specific deserialization issue while
maintaining existing validation behavior for new operator creation.
41a0719 to
80535cd
Compare
kaxil
added a commit
that referenced
this pull request
Sep 19, 2025
) Resolves an issue where DAGs using non default value like `weight_rule='absolute'` would fail during deserialization with `'Unknown priority strategy'` error. The problem occurred when the scheduler attempted to deserialize tasks that had already been converted to `PriorityWeightStrategy` instances. The `validate_and_load_priority_weight_strategy` function now properly handles cases where a `PriorityWeightStrategy` instance is passed, returning it directly instead of attempting to re-validate it. This fix ensures that all weight rule options (`downstream`, `upstream`, `absolute`) work correctly in the complete DAG processing pipeline including serialization, storage, and deserialization. To Reproduce the bug, run the following dag or just run the added unit test without code changes: ```py from airflow import DAG from airflow.sdk import task from airflow.task.weight_rule import WeightRule with DAG("xcom_backend_dag"): @task() def xcom_producer(): return "my_value" @task(weight_rule=WeightRule.ABSOLUTE) def xcom_consumer(value): assert value == "my_value" xcom_consumer(xcom_producer()) ``` which will then fail, when you try to trigger the dag from UI. Fix DAG deserialization failure with weight_rule='absolute' Resolves an issue where DAGs using weight_rule='absolute' would fail during deserialization with 'Unknown priority strategy' error. The problem occurred when the SerializedBaseOperator.weight_rule property was re-validating already-instantiated PriorityWeightStrategy instances. During deserialization, decode_priority_weight_strategy() creates strategy instances and stores them in _weight_rule, but the weight_rule property was calling validate_and_load_priority_weight_strategy() which expected a string or class, not an instance. Fixed by checking if _weight_rule is already a PriorityWeightStrategy instance in the property getter and returning it directly. User input still goes through proper validation. This targeted fix resolves the specific deserialization issue while maintaining existing validation behavior for new operator creation. (cherry picked from commit aece98b)
KatalKavya96
pushed a commit
to KatalKavya96/airflow
that referenced
this pull request
Sep 22, 2025
…che#55906) Resolves an issue where DAGs using non default value like `weight_rule='absolute'` would fail during deserialization with `'Unknown priority strategy'` error. The problem occurred when the scheduler attempted to deserialize tasks that had already been converted to `PriorityWeightStrategy` instances. The `validate_and_load_priority_weight_strategy` function now properly handles cases where a `PriorityWeightStrategy` instance is passed, returning it directly instead of attempting to re-validate it. This fix ensures that all weight rule options (`downstream`, `upstream`, `absolute`) work correctly in the complete DAG processing pipeline including serialization, storage, and deserialization. To Reproduce the bug, run the following dag or just run the added unit test without code changes: ```py from airflow import DAG from airflow.sdk import task from airflow.task.weight_rule import WeightRule with DAG("xcom_backend_dag"): @task() def xcom_producer(): return "my_value" @task(weight_rule=WeightRule.ABSOLUTE) def xcom_consumer(value): assert value == "my_value" xcom_consumer(xcom_producer()) ``` which will then fail, when you try to trigger the dag from UI. Fix DAG deserialization failure with weight_rule='absolute' Resolves an issue where DAGs using weight_rule='absolute' would fail during deserialization with 'Unknown priority strategy' error. The problem occurred when the SerializedBaseOperator.weight_rule property was re-validating already-instantiated PriorityWeightStrategy instances. During deserialization, decode_priority_weight_strategy() creates strategy instances and stores them in _weight_rule, but the weight_rule property was calling validate_and_load_priority_weight_strategy() which expected a string or class, not an instance. Fixed by checking if _weight_rule is already a PriorityWeightStrategy instance in the property getter and returning it directly. User input still goes through proper validation. This targeted fix resolves the specific deserialization issue while maintaining existing validation behavior for new operator creation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves an issue where DAGs using non default value like
weight_rule='absolute'would fail during deserialization with'Unknown priority strategy'error. The problem occurred when the scheduler attempted to deserialize tasks that had already been converted toPriorityWeightStrategyinstances.The
validate_and_load_priority_weight_strategyfunction now properly handles cases where aPriorityWeightStrategyinstance is passed, returning it directly instead of attempting to re-validate it.This fix ensures that all weight rule options (
downstream,upstream,absolute) work correctly in the complete DAG processing pipeline including serialization, storage, and deserialization.To Reproduce the bug, run the following dag or just run the added unit test without code changes:
which will then fail, when you try to trigger the dag from UI.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.