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/07/06 11:52:20 UTC

[GitHub] [airflow] kaxil commented on a change in pull request #16633: Support serialization of non-primitive values for classes extending BaseOperator and DAG

kaxil commented on a change in pull request #16633:
URL: https://github.com/apache/airflow/pull/16633#discussion_r664485095



##########
File path: tests/serialization/test_dag_serialization.py
##########
@@ -861,6 +892,30 @@ def __init__(self, do_xcom_push=False, **kwargs):
 
         assert serialized_op.do_xcom_push is False
 
+    def test_operator_custom_serialized_fields_present(self):
+        class MyOperator(BaseOperator):
+            __serialized_fields: Optional[frozenset] = None
+
+            def __init__(self, a_dictionary_value: Dict, **kwargs):
+                super().__init__(**kwargs)
+                self.a_dictionary_value = a_dictionary_value

Review comment:
       Why would you want this field in serialized json? if the reason is that it is template_filed, then this can pass right now without any changes to the actual code (only test change) as follows:
   
   ```python
       def test_operator_custom_serialized_fields_present(self):
           class MyOperator(BaseOperator):
   
               template_fields = (
                   'a_dictionary_value',
               )
   
               def __init__(self, a_dictionary_value: Dict, **kwargs):
                   super().__init__(**kwargs)
                   self.a_dictionary_value = a_dictionary_value
   
           my_simple_dict = {"a": 1337, "b": 7331}
           op = MyOperator(task_id="dummy", a_dictionary_value=my_simple_dict)
           assert op.a_dictionary_value == my_simple_dict
   
           blob = SerializedBaseOperator.serialize_operator(op)
           serialized_op = SerializedBaseOperator.deserialize_operator(blob)
   
           assert serialized_op.a_dictionary_value == my_simple_dict  # type: ignore # pylint: disable=no-member
   ```




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