diff --git a/CHANGELOG.md b/CHANGELOG.md index 6818447c69f8..3ed2ba5bba19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - Renamed `to_dotdict` -> `as_nested_dict` - [#339](https://github.com/PrefectHQ/prefect/pull/339) - Moved `prefect.utilities.collections.GraphQLResult` to `prefect.utilities.graphql.GraphQLResult` - [#371](https://github.com/PrefectHQ/prefect/pull/371) - `SynchronousExecutor` now does _not_ do depth first execution for mapped tasks - [#373](https://github.com/PrefectHQ/prefect/pull/373) +- Rename `NestedField.dump_fn` -> `NestedField.value_selection_fn` for clarity - [#377](https://github.com/PrefectHQ/prefect/pull/377) ## 0.3.3 diff --git a/src/prefect/serialization/flow.py b/src/prefect/serialization/flow.py index 1bb6ba36d1b1..361c06dde2bd 100644 --- a/src/prefect/serialization/flow.py +++ b/src/prefect/serialization/flow.py @@ -32,7 +32,7 @@ class Meta: environment = fields.Nested(EnvironmentSchema, allow_none=True) parameters = NestedField( ParameterSchema, - dump_fn=lambda obj, context: { + value_selection_fn=lambda obj, context: { p for p in getattr(obj, "tasks", []) if isinstance(p, prefect.core.task.Parameter) @@ -44,7 +44,7 @@ class Meta: reference_tasks = NestedField( TaskSchema, many=True, - dump_fn=lambda obj, context: getattr(obj, "_reference_tasks", []), + value_selection_fn=lambda obj, context: getattr(obj, "_reference_tasks", []), only=["id"], ) diff --git a/src/prefect/utilities/serialization.py b/src/prefect/utilities/serialization.py index 79af7aec7be4..2feecb52fbcf 100644 --- a/src/prefect/utilities/serialization.py +++ b/src/prefect/utilities/serialization.py @@ -206,19 +206,21 @@ def _deserialize(self, value, attr, data, **kwargs): class NestedField(fields.Nested): """ An extension of the Marshmallow Nested field that allows the value to be selected - via a dump_fn. + via a value_selection_fn. """ - def __init__(self, nested: type, dump_fn: Callable = None, **kwargs) -> None: + def __init__( + self, nested: type, value_selection_fn: Callable = None, **kwargs + ) -> None: super().__init__(nested=nested, **kwargs) - self.dump_fn = dump_fn + self.value_selection_fn = value_selection_fn - if dump_fn is not None: + if value_selection_fn is not None: self._CHECK_ATTRIBUTE = False def _serialize(self, value, attr, obj, **kwargs): - if self.dump_fn is not None: - value = self.dump_fn(obj, self.context) + if self.value_selection_fn is not None: + value = self.value_selection_fn(obj, self.context) return super()._serialize(value, attr, obj, **kwargs)