Jorricks commented on a change in pull request #16554:
URL: https://github.com/apache/airflow/pull/16554#discussion_r656040921
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -186,13 +186,18 @@ def serialize_to_json(
if cls._is_excluded(value, key, object_to_serialize):
continue
- if key in decorated_fields:
- serialized_object[key] = cls._serialize(value)
- else:
- value = cls._serialize(value)
- if isinstance(value, dict) and "__type" in value:
+ value = cls._serialize(value)
+ if key not in decorated_fields and isinstance(value, dict) and
"__type" in value:
+ # Extra check to make sure for custom operators or dags that
the non-standard
+ # serialized_fields still support non-primitive types (e.g.
dicts).
+ if isinstance(object_to_serialize, DAG) and key in
DAG.get_serialized_fields():
+ value = value["__var"]
+ elif (
+ isinstance(object_to_serialize, BaseOperator)
+ and key in BaseOperator.get_serialized_fields()
+ ):
Review comment:
The difference is that a person could extend the DAG class and implement
the `get_serialized_fields()` themselves.
Example from tests:
```python
class MyDAG(DAG):
__serialized_fields: Optional[frozenset] = None
def __init__(self, dag_id: str, a_tuple_value: Tuple, **kwargs):
super().__init__(dag_id, **kwargs)
self.a_tuple_value = a_tuple_value
@classmethod
def get_serialized_fields(cls):
if not cls.__serialized_fields:
custom_fields = {"a_tuple_value"}
cls.__serialized_fields =
frozenset(super().get_serialized_fields() | custom_fields)
return cls.__serialized_fields
```
In this case, the `a_tuple_value` would be in
`object_to_serialize.get_serialized_fields()` but would not be in
`DAG.get_serialized_fields()`.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]