You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/09/03 04:21:02 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #17989: Require timetable class be registered via plugin

uranusjr commented on a change in pull request #17989:
URL: https://github.com/apache/airflow/pull/17989#discussion_r701573209



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -128,22 +122,39 @@ def decode_timezone(var: Union[str, int]) -> Timezone:
     return pendulum.timezone(var)
 
 
-def encode_timetable(var: Timetable) -> Dict[str, Any]:
+def _get_registered_timetable(importable_string: str) -> Optional[Type[Timetable]]:
+    from airflow import plugins_manager
+
+    if importable_string.startswith("airflow.timetables."):
+        return import_string(importable_string)
+    plugins_manager.initialize_timetables_plugins()
+    return plugins_manager.timetable_classes.get(importable_string)
+
+
+def _encode_timetable(var: Timetable) -> Dict[str, Any]:
     """Encode a timetable instance.
 
     This delegates most of the serialization work to the type, so the behavior
     can be completely controlled by a custom subclass.
     """
-    return {"type": as_importable_string(type(var)), "value": var.serialize()}
+    timetable_class = type(var)
+    importable_string = as_importable_string(timetable_class)
+    if _get_registered_timetable(importable_string) != timetable_class:
+        raise AirflowException(f"Cannot encode unregistered timetable class {importable_string!r}")

Review comment:
       This exception is actually never shown in `ImportError` since `SerializedDAG.serialize_dag()` swallows it and shows *Failed to serialize DAG 'dag_id'* instead. I’ve modified the message to append what caused the serialisation failure.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org