def _deserialize_dag_params(cls, encoded_dag_params: Dict) -> ParamsDict: """Deserialize a DAGs Params dict""" op_params = {} for k, v in encoded_dag_params.items(): param_class = import_string(v['__class']) del v['__class'] op_params[k] = param_class(**v) return ParamsDict(op_params)
def _deserialize_operator_params( cls, encoded_op_params: Dict) -> Dict[str, Param]: """Deserialize Params dict of a operator""" op_params = {} for k, v in encoded_op_params.items(): param_class = import_string(v['__class']) del v['__class'] op_params[k] = param_class(**v) return ParamsDict(op_params)
def _serialize_params_dict(cls, params: ParamsDict): """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': 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') return serialized_params
def _deserialize_params_dict(cls, encoded_params: Dict) -> ParamsDict: """Deserialize a DAG's Params dict""" op_params = {} for k, v in encoded_params.items(): if isinstance(v, dict) and "__class" in v: op_params[k] = cls._deserialize_param(v) else: # Old style params, convert it op_params[k] = Param(v) return ParamsDict(op_params)
def _deserialize_params_dict(cls, encoded_params: Dict) -> ParamsDict: """Deserialize a DAGs Params dict""" op_params = {} for k, v in encoded_params.items(): if isinstance(v, dict) and "__class" in v: param_class = import_string(v['__class']) op_params[k] = param_class(**v) else: # Old style params, upgrade it op_params[k] = Param(v) return ParamsDict(op_params)
def _serialize_operator_params(cls, op_params: ParamsDict): """Serialize Params dict of a operator""" serialized_params = {} for k, v in op_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': serialized_params[k] = v.dump() else: raise ValueError( 'Params to a Task can be only of type airflow.models.param.Param' ) return serialized_params