kaxil opened a new pull request, #64557: URL: https://github.com/apache/airflow/pull/64557
- `TaskInstance.refresh_from_task()` and `insert_mapping()` call `task.weight_rule.get_weight()` unconditionally, but `BaseOperator` (task-sdk) stores `weight_rule` as a `WeightRule` enum -- a plain string with no `get_weight` method - Only `SerializedBaseOperator` has a [`@property`](https://github.com/astronomer/airflow/blob/main/airflow-core/src/airflow/serialization/definitions/baseoperator.py#L315-L318) that lazily converts the enum to a `PriorityWeightStrategy` (which has `get_weight`) - This breaks any code path that creates a `TaskInstance` from a non-serialized operator (tests, external tools, plugins) - Production scheduler is unaffected since it always uses serialized DAGs ## Fix Before calling `get_weight()`, check whether the `weight_rule` object supports it. If not, convert it via `validate_and_load_priority_weight_strategy()` -- the same function `SerializedBaseOperator` uses. Uses `hasattr` rather than `isinstance` so duck-typed custom strategies (`WeightRuleProtocol`) pass through without double-wrapping. ## Gotchas - The conversion only triggers for non-serialized operators (the `hasattr` check is a no-op for serialized ones that already have `get_weight`) - `WeightRuleProtocol` from [task-sdk/types.py](https://github.com/astronomer/airflow/blob/main/task-sdk/src/airflow/sdk/types.py) defines `get_weight` structurally, so `hasattr` is the correct check over `isinstance(PriorityWeightStrategy)` -- 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]
