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

AttributeError: 'coroutine' object has no attribute 'value' #15086

Closed
mahiki opened this issue Aug 26, 2024 · 2 comments
Closed

AttributeError: 'coroutine' object has no attribute 'value' #15086

mahiki opened this issue Aug 26, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mahiki
Copy link

mahiki commented Aug 26, 2024

Bug summary

I upgraded from 2.16.0 -> 2.20.3. All tests pass, but when I try to create deployments I get that async error like in #14712.
I think this was resolved in 2.19.9, or maybe this is a different but similar problem.

utility.py is a dependency of a flow I am deploying:

from prefect.blocks.core import Block

# just retrieving a string value from a block.
env_block_string = Block.load(name='string/environment').value

ddl.py imports the utility.py module above

from src.utility import a_function

@flow
def generic_function()
     x = a_function(yada, yada)

Partial stacktrace

Deploying all flows with an existing deployment configuration...
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Deploying sqlfile                                                                                                                                                                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Traceback (most recent call last):
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/merlinr/zillpo/zhl-wbr/src/deployments/ddl.py", line 3, in <module>
    from src.trino_flows import send_ddl
  File "/Users/merlinr/zillpo/zhl-wbr/src/trino_flows.py", line 14, in <module>
    from src.utility import flatten_list
  File "/Users/merlinr/zillpo/zhl-wbr/src/utility.py", line 11, in <module>
    env_block_string = Block.load(name=PREFECT_ENV_BLOCK).value
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'coroutine' object has no attribute 'value'

The above exception was the direct cause of the following exception:
# a bunch more

AttributeError: 'coroutine' object has no attribute 'value'
An exception occurred.
sys:1: RuntimeWarning: coroutine 'Block.load' was never awaited

Version info (prefect version output)

prefect version
Version:             2.20.3
API version:         0.8.4
Python version:      3.11.9
Git commit:          b8c27aa0
Built:               Thu, Aug 22, 2024 3:13 PM
OS/Arch:             darwin/arm64
Profile:             dev
Server type:         server

Additional context

I think I could try rolling back from 2.20.3 -> 2.19.9, or I saw somewhere I could try:

env_block_string = Block.load(name=PREFECT_ENV_BLOCK, _sync=True).value

Or perhaps I just need to move that Block.load into into the flow definition where it it used. I'd rather not do that, as I prefer to pull the string out as a variable declaration.

@mahiki mahiki added the bug Something isn't working label Aug 26, 2024
@mahiki
Copy link
Author

mahiki commented Aug 26, 2024

Update: I added Block.load(name=..., _sync=True).value

# I got this warning
RuntimeWarning: coroutine 'Block.load' was never awaited


╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Deploying deck_id                                                                                                                                                                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
$HOME/Library/Caches/pypoetry/virtualenvs/templisher-4hu7XBP5-py3.11/lib/python3.11/site-packages/prefect/utilities/importtools.py:511: RuntimeWarning: coroutine 'Block.load' was never awaited
  logger.debug("Failed to compile: %s", e)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
15:32:02.379 | WARNING | griffe - <module>:3: Failed to get 'name: description' pair from 'deck_id -- the name of the deck. These are listed in decks.yaml, and named in the file'
15:32:02.380 | WARNING | griffe - <module>:4: Failed to get 'name: description' pair from ''deck_id.yaml'.'
$HOME/Library/Caches/pypoetry/virtualenvs/templisher-4hu7XBP5-py3.11/lib/python3.11/site-packages/prefect/flows.py:1693: RuntimeWarning: coroutine 'Block.load' was never awaited
  if flow is None:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
15:32:02.382 | WARNING | griffe - <module>:3: Failed to get 'name: description' pair from 'deck_id -- the name of the deck. These are listed in decks.yaml, and named in the file'
15:32:02.382 | WARNING | griffe - <module>:4: Failed to get 'name: description' pair from ''deck_id.yaml'.'
Running deployment build steps...

Seems like the deployments will still run though...update to come.

Update: Yup, the deployment (with many subflows and tasks) completed successfully. Looks the the warnings on deployment did not result in errors.

This required that I put Block.load(name='xxxx', _sync=True) everywhere I loaded a block.

@cicdw
Copy link
Member

cicdw commented Aug 28, 2024

Hey @mahiki - yea, I haven't figured out what the precise change in async logic was that caused these coroutines to stop getting run synchronously under certain situations, but you're correct that the recommended solution is to set _sync=True to guarantee synchronous execution under all circumstances.

It looks like you've already seen this, but for others who comes along we plan to roll out more explicit dual interfaces for sync/async code to avoid these inevitable edge cases: #15008

I'm going to close this issue as the _sync flag resolves it, but thank you for raising and sharing your debugging and solution!

@cicdw cicdw closed this as completed Aug 28, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
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

7 participants
@mahiki @cicdw and others