Updated most python dependencies
Primarily FastAPI and Pydantic to v2. Also ruff to latest. Updated some code to support Pydantic v2
This commit is contained in:
@@ -120,6 +120,7 @@ class Database:
|
||||
|
||||
Returns:
|
||||
The path to the created backup or None if no backup was created.
|
||||
|
||||
"""
|
||||
if not self.is_file_based_sqlite() or self.connection_url.database is None:
|
||||
logger.info("Skipping backup as the database is not SQLite.")
|
||||
@@ -159,6 +160,7 @@ def setup_db(connection_url: URL) -> None:
|
||||
|
||||
Args:
|
||||
connection_url: The URL to connect to the database.
|
||||
|
||||
"""
|
||||
global __db # noqa: PLW0603
|
||||
__db = Database(connection_url)
|
||||
@@ -170,6 +172,7 @@ async def backup_global_db(num_backups: int = 5) -> Optional[Path]:
|
||||
|
||||
Returns:
|
||||
The path to the created backup or None if no backup was created.
|
||||
|
||||
"""
|
||||
if __db is None:
|
||||
raise RuntimeError("DB is not setup.")
|
||||
@@ -198,6 +201,7 @@ def schedule_tasks(scheduler: Scheduler) -> None:
|
||||
|
||||
Args:
|
||||
scheduler: The scheduler to use for scheduling tasks.
|
||||
|
||||
"""
|
||||
if __db is None:
|
||||
raise RuntimeError("DB is not setup.")
|
||||
@@ -218,6 +222,7 @@ async def get_db_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
|
||||
Yields:
|
||||
The database session.
|
||||
|
||||
"""
|
||||
if __db is None or __db.session_maker is None:
|
||||
raise RuntimeError("DB is not setup.")
|
||||
|
||||
@@ -261,7 +261,7 @@ async def use_weight_safe(db: AsyncSession, spool_id: int, weight: float) -> Non
|
||||
.where(models.Spool.id == spool_id)
|
||||
.values(
|
||||
used_weight=case(
|
||||
(models.Spool.used_weight + weight >= 0.0, models.Spool.used_weight + weight), # noqa: PLR2004
|
||||
(models.Spool.used_weight + weight >= 0.0, models.Spool.used_weight + weight),
|
||||
else_=0.0, # Set used_weight to 0 if the result would be negative
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user