feat: Enhance timestamp management in BaseModel and PlaylistRepository; add automatic updates and improve code readability
All checks were successful
Backend CI / lint (push) Successful in 9m21s
Backend CI / test (push) Successful in 4m0s

This commit is contained in:
JSC
2025-08-16 00:19:53 +02:00
parent b691649f7e
commit 4cec3b9d18
4 changed files with 38 additions and 3 deletions

View File

@@ -1,6 +1,9 @@
from datetime import UTC, datetime
from typing import Any
from sqlalchemy import event
from sqlalchemy.engine import Connection
from sqlalchemy.orm import Mapper
from sqlmodel import Field, SQLModel
@@ -16,6 +19,8 @@ class BaseModel(SQLModel):
# SQLAlchemy event listener to automatically update updated_at timestamp
@event.listens_for(BaseModel, "before_update", propagate=True)
def update_timestamp(mapper, connection, target):
def update_timestamp(
mapper: Mapper[Any], connection: Connection, target: BaseModel, # noqa: ARG001
) -> None:
"""Automatically set updated_at timestamp before update operations."""
target.updated_at = datetime.now(UTC)