<@ULVA73B9P> I'm deploying prefect with the GitRep...
# ask-marvin
r
@Marvin I'm deploying prefect with the GitRepository module. I'm having issues with loading Secret.load("secret-name") and coroutine issues with the .get() method on the Secret module. Is there a way to load the secret synchronously?
m
It looks like you're experiencing an issue that's been reported in the Prefect community. The problem arises when
Secret.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:
Copy code
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!