mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-08 17:03:11 -05:00
@@ -2,7 +2,7 @@ from abc import ABC
|
||||
from logging import Logger
|
||||
|
||||
from fastapi import Depends
|
||||
from pydantic import UUID4
|
||||
from pydantic import UUID4, ConfigDict
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from mealie.core.config import get_app_dirs, get_app_settings
|
||||
@@ -25,10 +25,10 @@ class _BaseController(ABC):
|
||||
session: Session = Depends(generate_session)
|
||||
translator: Translator = Depends(local_provider)
|
||||
|
||||
_repos: AllRepositories | None
|
||||
_logger: Logger | None
|
||||
_settings: AppSettings | None
|
||||
_folders: AppDirectories | None
|
||||
_repos: AllRepositories | None = None
|
||||
_logger: Logger | None = None
|
||||
_settings: AppSettings | None = None
|
||||
_folders: AppDirectories | None = None
|
||||
|
||||
@property
|
||||
def t(self):
|
||||
@@ -58,8 +58,7 @@ class _BaseController(ABC):
|
||||
self._folders = get_app_dirs()
|
||||
return self._folders
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
|
||||
|
||||
class BasePublicController(_BaseController):
|
||||
|
||||
@@ -6,11 +6,10 @@ See their repository for details -> https://github.com/dmontagu/fastapi-utils
|
||||
|
||||
import inspect
|
||||
from collections.abc import Callable
|
||||
from typing import Any, TypeVar, cast, get_type_hints
|
||||
from typing import Any, ClassVar, ForwardRef, TypeVar, cast, get_origin, get_type_hints
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi.routing import APIRoute
|
||||
from pydantic.typing import is_classvar
|
||||
from starlette.routing import Route, WebSocketRoute
|
||||
|
||||
T = TypeVar("T")
|
||||
@@ -47,6 +46,25 @@ def _cbv(router: APIRouter, cls: type[T], *urls: str, instance: Any | None = Non
|
||||
return cls
|
||||
|
||||
|
||||
# copied from Pydantic V1 Source: https://github.com/pydantic/pydantic/blob/1c91c8627b541b22354b9ed56b9ef1bb21ac6fbd/pydantic/v1/typing.py
|
||||
def _check_classvar(v: type[Any] | None) -> bool:
|
||||
if v is None:
|
||||
return False
|
||||
|
||||
return v.__class__ == ClassVar.__class__ and getattr(v, "_name", None) == "ClassVar"
|
||||
|
||||
|
||||
# copied from Pydantic V1 Source: https://github.com/pydantic/pydantic/blob/1c91c8627b541b22354b9ed56b9ef1bb21ac6fbd/pydantic/v1/typing.py
|
||||
def _is_classvar(ann_type: type[Any]) -> bool:
|
||||
if _check_classvar(ann_type) or _check_classvar(get_origin(ann_type)):
|
||||
return True
|
||||
|
||||
if ann_type.__class__ == ForwardRef and ann_type.__forward_arg__.startswith("ClassVar["): # type: ignore
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def _init_cbv(cls: type[Any], instance: Any | None = None) -> None:
|
||||
"""
|
||||
Idempotently modifies the provided `cls`, performing the following modifications:
|
||||
@@ -67,7 +85,7 @@ def _init_cbv(cls: type[Any], instance: Any | None = None) -> None:
|
||||
|
||||
dependency_names: list[str] = []
|
||||
for name, hint in get_type_hints(cls).items():
|
||||
if is_classvar(hint):
|
||||
if _is_classvar(hint):
|
||||
continue
|
||||
|
||||
if name.startswith("_"):
|
||||
|
||||
@@ -108,7 +108,7 @@ class HttpRepo(Generic[C, R, U]):
|
||||
)
|
||||
|
||||
try:
|
||||
item = self.repo.patch(item_id, data.dict(exclude_unset=True, exclude_defaults=True))
|
||||
item = self.repo.patch(item_id, data.model_dump(exclude_unset=True, exclude_defaults=True))
|
||||
except Exception as ex:
|
||||
self.handle_exception(ex)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user