Hi folks, we spotted a change in `0.14.11` that ma...
# ask-community
m
Hi folks, we spotted a change in
0.14.11
that made the Flow object no longer pickleable using
pickle
- I am wondering if others have bumped into this
Specifically it is due to the use of
lambda
in
Flow.___init___
in
self.__slug__counters
which raises this error
Copy code
AttributeError: Can't pickle local object 'Flow.__init__.<locals>.<lambda>'
i.e. it is this code block in
Flow.___init___
(
prefect/core/flow.py
)
Copy code
self._slug_counters = collections.defaultdict(
            lambda: itertools.count(1)
        )  # type: Dict[str, Iterator[int]]
changing this to use a named function addresses the pickling issue
i.e
Copy code
def count():
    return itertools.count(1)

self._slug_counters = collections.defaultdict(count)
happy to open a PR with this minor fix if need be
s
Are you using pickle or cloudpickle?
m
pickle
- sadly we are constrained to using pickle since we are using a prefect flow as part of a tensorflow 2.0 training
s
Hmm, in that case the easy solution disappears, and I hope a dev can offer some proper insight soon!
m
so as an update - we can circumvent this issue by subclassing
Flow
and adjusting the
subclassed.__init__
accordingly
j
Hi Marwan, we don't guarantee flows are pickleable (only cloudpickleable). Many tasks in prefect are only serializable via cloudpickle (e.g. any
@task
created task), so in practice pickle-only support is not a priority for us. That said, we'd accept a simple fix if you want. I'd use a
partial
here instead to avoid defining a top-level function.
m
Hi @Jim Crist-Harif - thanks for responding, that’s understandable … Sure will open a PR for this simple fix