Skip to content

Commit

Permalink
Better error when param value has unexpected type (#20648)
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Jan 5, 2022
1 parent 64c0bd5 commit a0cad07
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions airflow/serialization/serialized_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,18 @@ def _serialize_params_dict(cls, params: Union[ParamsDict, dict]):
"""Serialize Params dict for a DAG/Task"""
serialized_params = {}
for k, v in params.items():
# TODO: As of now, we would allow serialization of params which are of type Param only
if f'{v.__module__}.{v.__class__.__name__}' == 'airflow.models.param.Param':
# TODO: As of now, we would allow serialization of params which are of type Param only.
try:
class_identity = f"{v.__module__}.{v.__class__.__name__}"
except AttributeError:
class_identity = ""
if class_identity == "airflow.models.param.Param":
serialized_params[k] = cls._serialize_param(v)
else:
raise ValueError('Params to a DAG or a Task can be only of type airflow.models.param.Param')
raise ValueError(
f"Params to a DAG or a Task can be only of type airflow.models.param.Param, "
f"but param {k!r} is {v.__class__}"
)
return serialized_params

@classmethod
Expand Down

0 comments on commit a0cad07

Please sign in to comment.