Open wangxin688 opened 1 year ago
@dmontagu May I ask is the project still alive?
@wangxin688 I haven't looked at this in a while, but I will try to find some time in the near future (hopefully the next week or two, feel free to keep pinging me) to try to bring this up-to-date with more recent versions of fastapi, pydantic, etc., and address bugs.
Thanks. That will be great! Also sqlalchemy need to bump to 2.x version since a lot of excellent features bring out to us
Test Code:
from fastapi import Request, FastAPI, Depends, APIRouter from fastapi_utils.cbv import cbv def get_locale(request: Request): return request.headers.get("locale", "en_US") router = APIRouter() @router.get("/test") def get_test(locale=Depends(get_locale)): return {"locale": locale} @cbv(router) class TestRouter: locale = Depends(get_locale) @router.get("/test1") def get_test_cbv(self): print(self.locale) return {"locale": self.locale} app =FastAPI() app.include_router(router, prefix="")
result of
test
is{"locale": "en_US"}
result oftest1
is{ "locale": { "dependency": {}, "use_cache": true } }
Depends was not execute as print info:
INFO: Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit) Depends(get_locale) INFO: 127.0.0.1:56462 - "GET /test1 HTTP/1.1" 200 OK Depends(get_locale) INFO: 127.0.0.1:56462 - "GET /test1 HTTP/1.1" 200 OK
I just figured it out with implementing a locale context middleware. But I don't know it's a bug or something else. The source of cbv is really hard to understand for me, sadlly.
@dmontagu how about now?
one more things. Fastapi 0.95.0 is supporting Annoted
now, which is not working in cbv router.
Working on updating fastapi-utils
to work with latest versions of everything and get a new release out today. Will then look at the open PRs and issues and try to get some things fixed. Hoping to get to that this evening, if not, then during this upcoming week.
Test Code:
result of
test
is{"locale": "en_US"}
result oftest1
is{ "locale": { "dependency": {}, "use_cache": true } }
Depends was not execute as print info: