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

better common error section #15271

Merged
merged 5 commits into from
Sep 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions docs/3.0/resources/upgrade-to-prefect-3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,75 @@ This change affects you if: You're using agents from an early version of Prefect
</info>

In Prefect 2, agents were deprecated in favor of next-generation workers. Workers are now standard in Prefect 3. For detailed information on upgrading from agents to workers, please refer to our [upgrade guide](https://docs-3.prefect.io/3.0/resources/upgrade-agents-to-workers).

### Resolving common gotchas

#### `AttributeError: 'coroutine' object has no attribute <some attribute>`

When within an asynchronous task or flow context, if you do **not** `await` an asynchronous function or method, this error will be raised when you try to use the object.

To fix it, `await` the asynchronous function or method or use `_sync=True`.

For example, `Block`'s `load` method is asynchronous in an async context:
<CodeGroup>
```python Wrong
from prefect.blocks.system import Secret

async def my_async_function():
my_secret = Secret.load("my-secret")
print(my_secret.get()) # AttributeError: 'coroutine' object has no attribute 'get'
```

```python Correct
from prefect.blocks.system import Secret

async def my_async_function():
my_secret = await Secret.load("my-secret")
print(my_secret.get()) # This will work
```

```python Also Correct
from prefect.blocks.system import Secret

async def my_async_function():
my_secret = Secret.load("my-secret", _sync=True)
print(my_secret.get()) # This will work
```

</CodeGroup>
zzstoatzz marked this conversation as resolved.
Show resolved Hide resolved

#### `TypeError: object <some Type> can't be used in 'await' expression`

This error occurs when using the `await` keyword before an object that is not a coroutine.

To fix it, remove the `await`.
zzstoatzz marked this conversation as resolved.
Show resolved Hide resolved

For example, `my_task.submit(...)` is _always_ synchronous in Prefect 3.x:

<CodeGroup>
```python Incorrect
from prefect import flow, task

@task
async def my_task():
pass

@flow
async def my_flow():
future = await my_task.submit() # TypeError: object PrefectConcurrentFuture can't be used in 'await' expression
```

```python Correct
from prefect import flow, task

@task
async def my_task():
pass

@flow
async def my_flow():
future = my_task.submit() # This will work
```
</CodeGroup>

See the [Futures interface section](#futures-interface) for more information on this particular gotcha.