diff --git a/marketing_api/routes/base.py b/marketing_api/routes/base.py index 964daf4..5ad80e8 100644 --- a/marketing_api/routes/base.py +++ b/marketing_api/routes/base.py @@ -39,7 +39,7 @@ async def write_action( """Создать действие""" user_id = user.get("id") if user else None logger.debug(f"write_action by {user_id=}") - ai = ActionsInfo(**user_action_info.dict()) + ai = ActionsInfo(**user_action_info.model_dump()) db.session.add(ai) db.session.flush() if ai.user: @@ -95,7 +95,7 @@ async def http_error_handler(req, exc): app.add_middleware( DBSessionMiddleware, - db_url=settings.DB_DSN, + db_url=str(settings.DB_DSN), engine_args={"pool_pre_ping": True, "isolation_level": "AUTOCOMMIT"}, ) diff --git a/marketing_api/routes/models.py b/marketing_api/routes/models.py index f895ef5..4a0123b 100644 --- a/marketing_api/routes/models.py +++ b/marketing_api/routes/models.py @@ -1,24 +1,23 @@ -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class Base(BaseModel): - class Config: - orm_mode = True + model_config = ConfigDict(from_attributes=True) class ActionInfo(Base): - user_id: int | None + user_id: int | None = None action: str - additional_data: str | None - path_from: str | None - path_to: str | None + additional_data: str | None = None + path_from: str | None = None + path_to: str | None = None class User(Base): id: int - union_number: str | None + union_number: str | None = None class UserPatch(Base): - union_number: str | None - auth_user_id: int | None + union_number: str | None = None + auth_user_id: int | None = None diff --git a/marketing_api/settings.py b/marketing_api/settings.py index a602307..8e570db 100644 --- a/marketing_api/settings.py +++ b/marketing_api/settings.py @@ -1,7 +1,8 @@ import os from functools import lru_cache -from pydantic import BaseSettings, PostgresDsn +from pydantic import ConfigDict, PostgresDsn +from pydantic_settings import BaseSettings class Settings(BaseSettings): @@ -15,11 +16,7 @@ class Settings(BaseSettings): CORS_ALLOW_METHODS: list[str] = ['*'] CORS_ALLOW_HEADERS: list[str] = ['*'] - class Config: - """Pydantic BaseSettings config""" - - case_sensitive = True - env_file = ".env" + model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore") @lru_cache diff --git a/migrations/env.py b/migrations/env.py index 48a4976..020aee6 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -61,7 +61,7 @@ def run_migrations_online(): """ configuration = config.get_section(config.config_ini_section) - configuration['sqlalchemy.url'] = settings.DB_DSN + configuration['sqlalchemy.url'] = str(settings.DB_DSN) connectable = engine_from_config( configuration, prefix="sqlalchemy.", diff --git a/migrations/versions/0ea7185ac58b_useragent.py b/migrations/versions/0ea7185ac58b_useragent.py index aaa764b..aec50fe 100644 --- a/migrations/versions/0ea7185ac58b_useragent.py +++ b/migrations/versions/0ea7185ac58b_useragent.py @@ -5,8 +5,8 @@ Create Date: 2023-05-05 12:25:03.383848 """ -from alembic import op import sqlalchemy as sa +from alembic import op # revision identifiers, used by Alembic. diff --git a/requirements.txt b/requirements.txt index 888de4d..635979f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ SQLAlchemy gunicorn auth-lib-profcomff[fastapi] logging-profcomff +pydantic-settings \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index ecb766a..706b6e8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,7 +18,7 @@ def client(): @pytest.fixture(scope='session') def dbsession(): settings = get_settings() - engine = create_engine(settings.DB_DSN) + engine = create_engine(str(settings.DB_DSN)) TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base.metadata.create_all(bind=engine) yield TestingSessionLocal()