Lee-W commented on code in PR #66848:
URL: https://github.com/apache/airflow/pull/66848#discussion_r3385896131
##########
airflow-core/src/airflow/partition_mappers/base.py:
##########
@@ -139,20 +152,34 @@ def to_upstream(self, downstream_key: str) ->
frozenset[str]:
)
def serialize(self) -> dict[str, Any]:
- from airflow.serialization.encoders import encode_partition_mapper,
encode_window
+ # Builtin RollupMappers serialize through ``encode_partition_mapper``
+ # (encoders.py), not this method. Keep the two in sync: a new field
must
+ # be added there (and to ``encode_wait_policy``) too, or it is silently
+ # dropped for builtin instances.
+ from airflow.serialization.encoders import (
+ encode_partition_mapper,
+ encode_wait_policy,
+ encode_window,
+ )
return {
"upstream_mapper": encode_partition_mapper(self.upstream_mapper),
"window": encode_window(self.window),
+ "wait_policy": encode_wait_policy(self.wait_policy),
}
@classmethod
def deserialize(cls, data: dict[str, Any]) -> PartitionMapper:
- from airflow.serialization.decoders import decode_partition_mapper,
decode_window
+ from airflow.serialization.decoders import (
+ decode_partition_mapper,
+ decode_wait_policy,
+ decode_window,
+ )
return cls(
upstream_mapper=decode_partition_mapper(data["upstream_mapper"]),
window=decode_window(data["window"]),
+ wait_policy=decode_wait_policy(data["wait_policy"]),
Review Comment:
I'd prefer to keep the direct `data["wait_policy"]` access here.
`wait_policy` is guaranteed to be present in serialized data:
`RollupMapper.__init__` normalizes a `None` argument to `WaitForAll()`, and
`serialize()` (along with the builtin `encode_partition_mapper` path) always
emits the resolved policy — `self.wait_policy` is never `None`. So a missing
`"wait_policy"` key can only mean the serialized data is malformed, and there
we want it to fail loud rather than silently substitute `WaitForAll()` and mask
the corruption.
There's no backward-compatibility concern either: `RollupMapper` is new in
the unreleased 3.3, so no previously serialized Dag can lack the field.
--
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]