Skip to content

Commit

Permalink
Merge pull request #377 from PrefectHQ/rename-dump-fn
Browse files Browse the repository at this point in the history
MAINT: Rename dump_fn -> value_selection_fn
  • Loading branch information
jlowin authored Dec 2, 2018
2 parents 4b5ec79 + 411ea8f commit 91557dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Badge text="alpha" type="warn"/>

Expand Down
4 changes: 2 additions & 2 deletions src/prefect/serialization/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"],
)

Expand Down
14 changes: 8 additions & 6 deletions src/prefect/utilities/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 91557dc

Please sign in to comment.