Fabien Punin
03/14/2025, 4:51 PMMarvin
03/14/2025, 4:51 PMSecret.load method in Prefect 3.x. When you deploy your flow, the Secret.load call returns a coroutine, which needs to be awaited, hence the AttributeError you're seeing when trying to call .get() directly.
To resolve this, you should either:
1. Await the coroutine: If your class constructor can be made asynchronous, you can use await to retrieve the secret:
python
from prefect.blocks.system import Secret
class MyClass:
async def __init__(self):
self.secret = await Secret.load("my-secret")
# Usage within an async context
async def main():
my_instance = await MyClass()
2. Use the _sync flag: If you need to keep your constructor synchronous, you can use the _sync=True flag to force synchronous execution:
python
from prefect.blocks.system import Secret
class MyClass:
def __init__(self):
self.secret = Secret.load("my-secret", _sync=True)
# Usage in a synchronous context
my_instance = MyClass()
For more details, you can refer to the Prefect 3.x documentation on blocks or check out related GitHub issues discussing similar problems.
If you have further questions or need additional assistance, feel free to ask.