You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining a flow, it's common to specify a custom result store. However, in Prefect V3 (and not V2), there is a check that the result store block has been saved that is executed in the decorator: code.
This makes it difficult to work with, as flow decorators are executed at import time, and there are several situations where one may not be in a good state to communicate with a Prefect server.
A simple and blocking example of such a state is when running tests with pytest. The following code would work fine in V2:
fromprefectimportflowfromprefect.resultsimportLocalFileSystemfromprefect.testing.utilitiesimportprefect_test_harness# The result store has not been saved, and that cannot be done at import time as we're not yet connected to a prefect server@flow(result_storage=LocalFileSystem())defmy_flow():
return"hello"deftest_my_flow():
withprefect_test_harness():
result=my_flow()
assertresult=="hello"
If you are not logged into prefect, running pytest will fail, with the following stack trace:
This is problematic, as there is no simple way (that I'm aware of) to create flows in decorators and refer to file systems that are not yet saved.
In my opinion, the existence / save check should be run at flow evaluation / deployment time. Or, it should be documented more clearly that one should refer to a storage block by name in decorators and ensure they are saved.
Version info
Version: 3.1.11
API version: 0.8.4
Python version: 3.13.1
Git commit: e448bd34
Built: Thu, Jan 2, 2025 1:11 PM
OS/Arch: darwin/arm64
Profile: default
Server type: unconfigured
Pydantic version: 2.10.4
Additional context
No response
The text was updated successfully, but these errors were encountered:
Thanks - that is near enough what we ended up doing, but it took us a while to figure it out.
I think the interface or documentation should be more clear or express more clearly that in non-trivial examples one should refer to result stores by name.
I'd be happy to contribute a PR with a docs change.
Bug summary
When defining a flow, it's common to specify a custom result store. However, in Prefect V3 (and not V2), there is a check that the result store block has been saved that is executed in the decorator: code.
This makes it difficult to work with, as
flow
decorators are executed at import time, and there are several situations where one may not be in a good state to communicate with a Prefect server.A simple and blocking example of such a state is when running tests with
pytest
. The following code would work fine in V2:If you are not logged into prefect, running pytest will fail, with the following stack trace:
This is problematic, as there is no simple way (that I'm aware of) to create flows in decorators and refer to file systems that are not yet saved.
In my opinion, the existence / save check should be run at flow evaluation / deployment time. Or, it should be documented more clearly that one should refer to a storage block by name in decorators and ensure they are saved.
Version info
Additional context
No response
The text was updated successfully, but these errors were encountered: