Closed Nnonexistent closed 10 months ago
@Nnonexistent great job! I found not only FastDepends
, but FastAPI
bug too 😃
I'll take a look, what I can do with it
FastAPI in this case hase the same error
from __future__ import annotations
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel
def main():
app = FastAPI()
class M(BaseModel):
m: str
@app.post("/")
async def handler(m: M):
print(m)
with TestClient(app) as client:
r = client.post("/", json={"m": "Hi!"})
print(r.json())
main()
pydantic.errors.PydanticUndefinedAnnotation: name 'M' is not defined
If both of the following conditions are met, the
PydanticUserError
exception is raised during function call:from __future__ import annotations
or, even, just with string annotations)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:
PS. Nice libraries, keep up great work!