ferruzzi commented on code in PR #61461:
URL: https://github.com/apache/airflow/pull/61461#discussion_r2898336759


##########
airflow-core/src/airflow/models/deadline_alert.py:
##########
@@ -86,6 +86,8 @@ def matches_definition(self, other: DeadlineAlert) -> bool:
     @property
     def reference_class(self) -> 
type[SerializedReferenceModels.SerializedBaseDeadlineReference]:
         """Return the deserialized reference class."""
+        if "__class_path" in self.reference:
+            return SerializedReferenceModels.SerializedCustomReference

Review Comment:
   that would extend elsewhere too, obviously.   Your new decoder would be 
something like 
   
   ```python
   def decode_deadline_reference(reference_data: dict):
       ref_name = 
reference_data.get(SerializedReferenceModels.REFERENCE_TYPE_FIELD)
       reference_class = (
           SerializedReferenceModels.get_reference_class(ref_name) 
           if ref_name in SerializedReferenceModels.get_builtin_references() 
           else SerializedReferenceModels.SerializedCustomReference
       )
       return reference_class.deserialize_reference(reference_data)
   ```
   
   and so on??
   
   Or take it a step further and have the helper accept a reference and return 
a bool if it is a builtin?
   
   ```python
   def is_builtin_reference(cls, ref_name):
       return any(
           reference.__name__ == ref_name
           for reference in var(cls).values()
           if issubclass(reference, cls.SerializedBaseDeadlineReference)
       )
   ```
   
   then the decoder is just 
   ```pyhthon
   def decode_deadline_reference(reference_data: dict):
       ref_name = 
reference_data.get(SerializedReferenceModels.REFERENCE_TYPE_FIELD)
       reference_class = (
           SerializedReferenceModels.get_reference_class(ref_name)
           if SerializedReferenceModels.is_builtin_reference(ref_name)
           else SerializedReferenceModels.SerializedCustomReference
       )
       return reference_class.deserialize_reference(reference_data)
   ```
   
   
   
   
   Just a thought since it looks like you were considering options.



-- 
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]

Reply via email to