From 408441b96c17c49d011714cf4037ecb95ed611ee Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Thu, 12 Oct 2023 23:55:43 +0100 Subject: [PATCH] fix: pydantic & sqlalchemy deprecation warnings --- src/backend/app/config.py | 8 ++++---- src/backend/app/db/database.py | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/backend/app/config.py b/src/backend/app/config.py index 4d89116e15..43732cf153 100644 --- a/src/backend/app/config.py +++ b/src/backend/app/config.py @@ -20,7 +20,7 @@ from functools import lru_cache from typing import Any, Optional, Union -from pydantic import Extra, FieldValidationInfo, PostgresDsn, field_validator +from pydantic import FieldValidationInfo, PostgresDsn, field_validator from pydantic_settings import BaseSettings, SettingsConfigDict @@ -94,7 +94,7 @@ def assemble_db_connection(cls, v: Optional[str], info: FieldValidationInfo) -> path=info.data.get("FMTM_DB_NAME", ""), ) # Convert Url type to string - return str(pg_url) + return pg_url ODK_CENTRAL_URL: Optional[str] = "" ODK_CENTRAL_USER: Optional[str] = "" @@ -111,7 +111,7 @@ def assemble_db_connection(cls, v: Optional[str], info: FieldValidationInfo) -> SENTRY_DSN: Optional[str] = None model_config = SettingsConfigDict( - case_sensitive=True, env_file=".env", extra=Extra.allow + case_sensitive=True, env_file=".env", extra="allow" ) @@ -120,7 +120,7 @@ def get_settings(): """Cache settings when accessed throughout app.""" _settings = Settings() if _settings.DEBUG: - print(f"Loaded settings: {_settings.dict()}") + print(f"Loaded settings: {_settings.model_dump()}") return _settings diff --git a/src/backend/app/db/database.py b/src/backend/app/db/database.py index 2e0328221a..714c381c64 100644 --- a/src/backend/app/db/database.py +++ b/src/backend/app/db/database.py @@ -19,12 +19,11 @@ """Config for the FMTM database connection.""" from sqlalchemy import create_engine -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import declarative_base, sessionmaker from app.config import settings -engine = create_engine(settings.FMTM_DB_URL) +engine = create_engine(settings.FMTM_DB_URL.unicode_string()) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base = declarative_base()