Ridhwan
10/13/2024, 4:58 AMMarvin
10/13/2024, 4:58 AMSecret.load("secret-name")
unexpectedly returns a coroutine in contexts where synchronous execution was expected, causing errors like AttributeError: 'coroutine' object has no attribute 'get'
.
The issue indicates that the Block.load
function in Prefect may return a coroutine depending on the context it's called from, particularly if it's used in an asynchronous environment.
For Prefect 2, to work around this, you may consider using the await
keyword when calling these methods in an async function, or ensure the operation is handled within an async function context. Alternatively, you can run these functions using synchronous compatibility utilities Prefect provides, such as:
python
from prefect.utilities.asyncutils import run_sync_in_worker_thread
secret_value = run_sync_in_worker_thread(lambda: Secret.load("secret-name").result().get())
This approach runs the secret loading task in a thread that manages to call async functions synchronously.
If you're upgrading or working with Prefect 3.x, consult the detailed documentation for any syntax or feature updates regarding secrets.
For more troubleshooting, refer to ongoing discussions and GitHub issues that address similar challenges.
If you encounter continued difficulty, consider submitting a new issue or contributing to existing threads for real-time support!