amoghrajesh commented on code in PR #61461:
URL: https://github.com/apache/airflow/pull/61461#discussion_r2916712431
##########
airflow-core/src/airflow/serialization/encoders.py:
##########
@@ -201,19 +201,43 @@ def encode_deadline_alert(d: DeadlineAlert |
SerializedDeadlineAlert) -> dict[st
from airflow.sdk.serde import serialize
return {
- "reference": d.reference.serialize_reference(),
+ "reference": encode_deadline_reference(d.reference),
"interval": d.interval.total_seconds(),
"callback": serialize(d.callback),
}
+_BUILTIN_DEADLINE_MODULES = (
+ "airflow.sdk.definitions.deadline",
+ "airflow.serialization.definitions.deadline",
+ # Include airflow.models.deadline to treat core's deadline references as
builtins.
+ # This is to maintain backcompat with 3.1.x custom refs that inherit from
+ # airflow.models.deadline.ReferenceModels.BaseDeadlineReference.
+ "airflow.models.deadline",
+)
+
+
def encode_deadline_reference(ref) -> dict[str, Any]:
"""
Encode a deadline reference.
+ For custom (non-builtin) deadline references, includes the class path
+ so the decoder can import the user's class at runtime.
+
:meta private:
"""
- return ref.serialize_reference()
+ from airflow._shared.module_loading import qualname
+
+ serialized = ref.serialize_reference()
+
+ # Custom types (not built-in) need __class_path so the decoder can import
them.
+ # Unlike built-in types which are looked up in SerializedReferenceModels,
+ # custom types are discovered via import_string(__class_path) at
deserialization time.
+ module = type(ref).__module__
+ if module not in _BUILTIN_DEADLINE_MODULES:
Review Comment:
Resolving this for now, do let me know if you disagree, we can handle in a
follow up
--
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]