Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeWarning: coroutine 'Variable.aget' was never awaited #16987

Open
EmilRex opened this issue Feb 5, 2025 · 2 comments
Open

RuntimeWarning: coroutine 'Variable.aget' was never awaited #16987

EmilRex opened this issue Feb 5, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@EmilRex
Copy link
Contributor

EmilRex commented Feb 5, 2025

Bug summary

When deploying a flow that gets a variable in the root of the file, a runtime warning is raised. This is not the case when directly invoking the flow:

# prefect variable set foo bar
from prefect import flow, get_run_logger
from prefect.variables import Variable

var = Variable.get("foo")

@flow
def hello():
    logger = get_run_logger()
    logger.info(f"Hello, {var}!")

if __name__ == "__main__":
    hello()

Running the flow works as expected:

$ python flow.py
13:28:01.628 | INFO    | Flow run 'ancient-labradoodle' - Beginning flow run 'ancient-labradoodle' for flow 'hello'
13:28:01.631 | INFO    | Flow run 'ancient-labradoodle' - View at https://app.prefect.cloud/account/0ff44498-d380-4d7b-bd68-9b52da03823f/workspace/6bf6d7a9-ab18-4942-9315-349d4f1fef34/runs/flow-run/eb104141-322a-43cd-b4c0-999d445c2ac4
13:28:01.632 | INFO    | Flow run 'ancient-labradoodle' - Hello, bar!
13:28:01.781 | INFO    | Flow run 'ancient-labradoodle' - Finished in state Completed()

However, deploying it fails:

$ prefect --no-prompt deploy flow.py:hello --name served --pool process
Unable to read the specified config file. Reason: [Errno 2] No such file or directory: 'prefect.yaml'. Skipping.
Your Prefect workers will attempt to load your flow from: /Users/emilchristensen/github/examples/flow.py. To see more options for 
managing your flow's code, run:

        $ prefect init

╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Deployment 'hello/served' successfully created with id '15f1662b-a874-452b-b366-826d3ddb04b5'.                                                     │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

View Deployment in UI: https://app.prefect.cloud/account/0ff44498-d380-4d7b-bd68-9b52da03823f/workspace/6bf6d7a9-ab18-4942-9315-349d4f1fef34/deployments/deployment/15f1662b-a874-452b-b366-826d3ddb04b5


To schedule a run for this deployment, use the following command:

        $ prefect deployment run 'hello/served'

sys:1: RuntimeWarning: coroutine 'Variable.aget' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

The last two lines specifically are what seem to problematic:

sys:1: RuntimeWarning: coroutine 'Variable.aget' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Version info

Version:             3.1.15
API version:         0.8.4
Python version:      3.12.8
Git commit:          3ac3d548
Built:               Thu, Jan 30, 2025 11:31 AM
OS/Arch:             darwin/arm64
Profile:             dev
Server type:         cloud
Pydantic version:    2.10.6
Integrations:
  prefect-docker:    0.6.2

Additional context

No response

@EmilRex EmilRex added the bug Something isn't working label Feb 5, 2025
@cicdw
Copy link
Member

cicdw commented Feb 5, 2025

I see, that's tricky - the recommended workaround for now is to set

var = Variable.get("foo", _sync=True)

@EmilRex
Copy link
Contributor Author

EmilRex commented Feb 5, 2025

I see, that's tricky - the recommended workaround for now is to set

var = Variable.get("foo", _sync=True)

Ah, I didn't realize you could do that... that's a solid work around, thank you @cicdw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants