mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
fix(backend): correct three small typing faults mypy now reports (#4709)
This commit is contained in:
@@ -36,11 +36,16 @@ from handler.auth.constants import (
|
||||
oauth2_password_bearer = OAuth2PasswordBearer(
|
||||
tokenUrl="/token",
|
||||
auto_error=False,
|
||||
# The maps are keyed by Scope, which is a StrEnum; FastAPI wants plain str.
|
||||
scopes={
|
||||
**READ_SCOPES_MAP,
|
||||
**WRITE_SCOPES_MAP,
|
||||
**EDIT_SCOPES_MAP,
|
||||
**FULL_SCOPES_MAP,
|
||||
str(scope): description
|
||||
for scope_map in (
|
||||
READ_SCOPES_MAP,
|
||||
WRITE_SCOPES_MAP,
|
||||
EDIT_SCOPES_MAP,
|
||||
FULL_SCOPES_MAP,
|
||||
)
|
||||
for scope, description in scope_map.items()
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -3037,14 +3037,14 @@ class DBRomsHandler(DBBaseHandler):
|
||||
row = session.execute(
|
||||
self._music_facet_joins(
|
||||
select(
|
||||
func.count().label("count"),
|
||||
func.count().label("total"),
|
||||
func.coalesce(func.sum(TrackMeta.duration_seconds), 0.0).label(
|
||||
"duration"
|
||||
),
|
||||
)
|
||||
).where(*where)
|
||||
).one()
|
||||
return int(row.count or 0), float(row.duration or 0.0)
|
||||
return int(row.total or 0), float(row.duration or 0.0)
|
||||
|
||||
@begin_session
|
||||
def get_music_game_genre_facet(
|
||||
@@ -3090,10 +3090,10 @@ class DBRomsHandler(DBBaseHandler):
|
||||
session=session,
|
||||
)
|
||||
per_rom = self._music_facet_joins(
|
||||
select(Rom.id.label("rom_id"), func.count().label("count"))
|
||||
select(Rom.id.label("rom_id"), func.count().label("total"))
|
||||
).where(*where)
|
||||
counts_by_rom = {
|
||||
row.rom_id: row.count
|
||||
row.rom_id: row.total
|
||||
for row in session.execute(per_rom.group_by(Rom.id)).all()
|
||||
}
|
||||
if not counts_by_rom:
|
||||
|
||||
@@ -8,6 +8,10 @@ from sqlalchemy.dialects import postgresql as sa_pg
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql import ColumnElement, func
|
||||
|
||||
# What `Session.get_bind()` returns; these helpers only read `.engine`, which
|
||||
# an Engine answers with itself.
|
||||
type DatabaseBind = sa.Engine | sa.Connection
|
||||
|
||||
# Single-column foreign keys that MariaDB/MySQL index implicitly but PostgreSQL
|
||||
# does not, so 0124 creates them there only and no model declares them.
|
||||
POSTGRESQL_FK_INDEXES: tuple[tuple[str, str, str], ...] = (
|
||||
@@ -47,7 +51,7 @@ def CustomJSON(**kwargs: Any) -> sa.JSON:
|
||||
|
||||
|
||||
def is_db_version_compatible(
|
||||
conn: sa.Connection,
|
||||
conn: DatabaseBind,
|
||||
min_version: tuple[int, ...] | None = None,
|
||||
) -> bool:
|
||||
"""Check if the database server version complies with the given version constraints."""
|
||||
@@ -58,20 +62,20 @@ def is_db_version_compatible(
|
||||
|
||||
|
||||
def is_postgresql(
|
||||
conn: sa.Connection, min_version: tuple[int, ...] | None = None
|
||||
conn: DatabaseBind, min_version: tuple[int, ...] | None = None
|
||||
) -> bool:
|
||||
if conn.engine.name != "postgresql":
|
||||
return False
|
||||
return is_db_version_compatible(conn, min_version=min_version)
|
||||
|
||||
|
||||
def is_mysql(conn: sa.Connection, min_version: tuple[int, ...] | None = None) -> bool:
|
||||
def is_mysql(conn: DatabaseBind, min_version: tuple[int, ...] | None = None) -> bool:
|
||||
if conn.engine.name != "mysql":
|
||||
return False
|
||||
return is_db_version_compatible(conn, min_version=min_version)
|
||||
|
||||
|
||||
def is_mariadb(conn: sa.Connection, min_version: tuple[int, ...] | None = None) -> bool:
|
||||
def is_mariadb(conn: DatabaseBind, min_version: tuple[int, ...] | None = None) -> bool:
|
||||
if conn.engine.name != "mariadb":
|
||||
return False
|
||||
return is_db_version_compatible(conn, min_version=min_version)
|
||||
@@ -168,7 +172,7 @@ def json_array_contains_value(
|
||||
if isinstance(value, str):
|
||||
return sa.type_coerce(column, sa_pg.JSONB).has_key(value)
|
||||
return sa.type_coerce(column, sa_pg.JSONB).contains(
|
||||
func.cast(value, sa_pg.JSONB)
|
||||
func.cast(sa.literal(value, sa_pg.JSONB), sa_pg.JSONB)
|
||||
)
|
||||
elif is_mysql(conn) or is_mariadb(conn):
|
||||
# In MySQL and MariaDB, JSON_CONTAINS requires a JSON-formatted string (even if it's an int).
|
||||
|
||||
Reference in New Issue
Block a user