Django db cleanup: explicitly add it to dependencies.

We can't really add it manually, because some of the deps are auto included as
parameters. These were not being decorated which in turn meeant issues.
This commit is contained in:
Tom Hacohen
2020-12-31 10:03:16 +02:00
parent 5b8f667e55
commit 2e21fe4994
5 changed files with 17 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
import typing as t
from fastapi import params
from fastapi.routing import APIRoute, get_request_handler
from pydantic import BaseModel
from starlette.requests import Request
@@ -38,21 +37,9 @@ class MsgpackRoute(APIRoute):
# keep track of content-type -> response classes
ROUTES_HANDLERS_CLASSES = {MsgpackResponse.media_type: MsgpackResponse}
def __init__(
self,
path: str,
endpoint: t.Callable[..., t.Any],
*args,
dependencies: t.Optional[t.Sequence[params.Depends]] = None,
**kwargs
):
if dependencies is not None:
dependencies = [
params.Depends(django_db_cleanup_decorator(dep.dependency), use_cache=dep.use_cache)
for dep in dependencies
]
def __init__(self, path: str, endpoint: t.Callable[..., t.Any], *args, **kwargs):
endpoint = django_db_cleanup_decorator(endpoint)
super().__init__(path, endpoint, *args, dependencies=dependencies, **kwargs)
super().__init__(path, endpoint, *args, **kwargs)
def _get_media_type_route_handler(self, media_type):
return get_request_handler(