Closed
Description
If both of the following conditions are met, the PydanticUserError
exception is raised during function call:
- ForwardRef annotations for arguments (e.g. with
from __future__ import annotations
or, even, just with string annotations) - Usage of non-global context. For example in attempt to dynamically create inject in wrapped function.
My particular case was from usage of faststream
, where I needed dynamically attach broker to different handlers. It all works well, but I have to be careful not to switch forward refs by accident.
Reproduction:
from __future__ import annotations # all is working if you comment this line
import asyncio
from pydantic import BaseModel
from fast_depends import inject
def container_function():
class Model(BaseModel):
num: int
@inject
async def main(a: Model):
pass
return main
main = container_function()
asyncio.run(main({"num": 1}))
PS. Nice libraries, keep up great work!
Metadata
Metadata
Assignees
Labels
No labels