https://prefect.io logo
Title
j

Josh Greenhalgh

03/15/2021, 3:28 PM
Haha Me again! So I am having some trouble with attaching
Result
classes to my flows. If I specify the result class in the same file that the flow is defined via
flow.result = ...
everything works as expected. However if I import the flow def and then attach the result class (same way just outside the flow def) I do not get any stored results. I have put together a minimal repo here -> https://github.com/josh-gree2/minimal-repo/compare/result-in-cli...master (the two branches show what I mean)
So on
master
all works as expected,
result-in-cli
not so much...
z

Zanie

03/15/2021, 3:43 PM
I must say, this is weird.
j

Josh Greenhalgh

03/15/2021, 3:45 PM
Are you able to reproduce?
z

Zanie

03/15/2021, 3:46 PM
I haven't tried to yet. Just trusting your example 😄
I don't see anything that would cause this
j

Josh Greenhalgh

03/15/2021, 3:46 PM
Could it be to do with the way I am renaming the flow object in the
__init__.py
perhaps?
z

Zanie

03/15/2021, 3:47 PM
Not afaik
j

Josh Greenhalgh

03/15/2021, 4:01 PM
The reason this is important for me is because I need to be able to easily switch between local dev (docker run config, local results with a mount) and production deploy (k8s run config, GCS result) - I deal with the differences within a cli which attaches the desired run config and result storage at registration time
z

Zanie

03/15/2021, 4:12 PM
So this looks like it arises because the
result
is not serialized in the Flow object, so the result type attached to a flow is loaded when the flow is loaded from storage
@Marvin open "`flow.result` type cannot be set dynamically at registration time"
j

Josh Greenhalgh

03/15/2021, 4:17 PM
Ok so when it's "Loaded from Storage" in my case this is the flow as it appears in the flow def file (without the storage class attached) because I use module storage? So can I mitigate in anyway?
z

Zanie

03/15/2021, 4:18 PM
You'll have to set the result in the flow def file, a possible work around is to add an environment variable to your run config and use that to dynamically set the result in your flow
flow.result = None if not os.environ.get("RESULT_TYPE") else ...
?
j

Josh Greenhalgh

03/15/2021, 4:19 PM
Ahh ok yeah that could work - will give it a try
Ok that seems to work! It will only be the value of the env var at runtime thats important yeah? When I register it it doesn't matter which result class gets attatched?
So as long as I set correctly in docker/k8s run config respectively all good?
z

Zanie

03/15/2021, 4:35 PM
Yep
j

Josh Greenhalgh

03/15/2021, 4:36 PM
Much thanks! Will keep an eye on that issue - it should behave as I expected yeah?
z

Zanie

03/15/2021, 4:37 PM
I'm not sure. It may be because we support custom result types which we can't serialize.
It should be documented at least