Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserializing Params where the default is an array #27944

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions airflow/serialization/serialized_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,19 @@ def _deserialize_param(cls, param_dict: dict):
class_: type[Param] = import_string(class_name)
attrs = ("default", "description", "schema")
kwargs = {}

def is_serialized(val):
if isinstance(val, dict):
return Encoding.TYPE in val
if isinstance(val, list):
return all(isinstance(item, dict) and Encoding.TYPE in item for item in val)
return False

for attr in attrs:
if attr not in param_dict:
continue
val = param_dict[attr]
is_serialized = (isinstance(val, dict) and Encoding.TYPE in val) or (
isinstance(val, list) and all(Encoding.TYPE in param for param in val)
)
if is_serialized:
if is_serialized(val):
deserialized_val = cls.deserialize(param_dict[attr])
kwargs[attr] = deserialized_val
else:
Expand Down
1 change: 1 addition & 0 deletions tests/serialization/test_dag_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def __init__(self, path: str):
Param("my value", description="hello", schema={"type": "string"}),
Param("my value", description="hello"),
Param(None, description=None),
Param([True], type="array", items={"type": "boolean"}),
],
)
def test_full_param_roundtrip(self, param):
Expand Down