Skip to content

Fix DAG deserialization failure with non-default weight_rule#55906

Merged
kaxil merged 1 commit into
apache:mainfrom
astronomer:fix-weight-rule
Sep 19, 2025
Merged

Fix DAG deserialization failure with non-default weight_rule#55906
kaxil merged 1 commit into
apache:mainfrom
astronomer:fix-weight-rule

Conversation

@kaxil

@kaxil kaxil commented Sep 19, 2025

Copy link
Copy Markdown
Member

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:

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.


^ 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.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

Comment thread airflow-core/tests/unit/serialization/test_dag_serialization.py Outdated

@ashb ashb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tests not happy now, but lgtm otherwise

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.
@kaxil kaxil merged commit aece98b into apache:main Sep 19, 2025
80 checks passed
@kaxil kaxil deleted the fix-weight-rule branch September 19, 2025 22:51
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.
@kaxil kaxil modified the milestones: Airflow 3.1.1, Airflow 3.1.0 Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants