Janet Carson
09/23/2024, 10:28 PMprefect.runtime.flow_run.id is not None
is trying to create a sqlite database in a directory that it's not allowed to write to when trying to access the prefect.runtime object.Will
09/24/2024, 12:15 AMprefect.runtime
is the way to do it. But since this is a test, you could use the prefect_test_harness() which would avoid trying to hit an actual database: https://docs.prefect.io/3.0/develop/test-workflowsJanet Carson
09/24/2024, 3:20 PMJanet Carson
09/24/2024, 5:10 PMRuntimeError: Timed out while attempting to connect to ephemeral Prefect API server.
before I even got to my test body
• There are screenfuls of sqlalchemy exceptions before the final failure messageNate
09/25/2024, 5:33 PMget_run_context
Nate
09/25/2024, 5:34 PMIn [1]: from prefect import flow
In [2]: from prefect.context import get_run_context
In [3]: @flow
...: def f(): print(get_run_context())
In [4]: f()
12:34:23.116 | INFO | prefect.engine - Created flow run 'attentive-jackdaw' for flow 'f'
12:34:23.119 | INFO | prefect.engine - View at ...
12:34:23.565 | INFO | Flow run 'attentive-jackdaw' - Finished in state Completed()
In [5]: f.fn()
---------------------------------------------------------------------------
MissingContextError Traceback (most recent call last)
Cell In[5], line 1
----> 1 f.fn()
Cell In[3], line 2, in f()
1 @flow
----> 2 def f(): print(get_run_context())
File ~/github.com/prefecthq/prefect/src/prefect/context.py:499, in get_run_context()
496 if flow_run_ctx:
497 return flow_run_ctx
--> 499 raise MissingContextError(
500 "No run context available. You are not in a flow or task run context."
501 )
MissingContextError: No run context available. You are not in a flow or task run context.
Janet Carson
09/25/2024, 5:34 PMNate
09/25/2024, 5:35 PMthe whole ephemeral database thing is just a mess in my isolated build environment so I'm just carrying around a variable and checking whether to call my_task or my_task.fnim interested to hear more about this if you don't mind explaining!
Janet Carson
09/25/2024, 5:37 PMwith prefect_test_harness()
fixture as suggested in the docs ( https://docs.prefect.io/3.0/develop/test-workflows) before I even got to the beginning of my test either in the build environment, and that also happened on my local dev machine if I did prefect cloud logout
before trying to run the tests.Janet Carson
09/25/2024, 5:38 PMNate
09/25/2024, 5:38 PM