diff --git a/app/repositories/maps.py b/app/repositories/maps.py index 2b6b9d68..41fbc58a 100644 --- a/app/repositories/maps.py +++ b/app/repositories/maps.py @@ -9,6 +9,8 @@ from app._typing import _UnsetSentinel from app._typing import UNSET +from app.utils import remove_none_values + # +--------------+------------------------+------+-----+---------+-------+ # | Field | Type | Null | Key | Default | Extra | # +--------------+------------------------+------+-----+---------+-------+ @@ -196,7 +198,7 @@ async def fetch_one( "filename": filename, } map = await app.state.services.database.fetch_one( - " ".join(q for q in queries if q is not None), params + " ".join(q for q in queries if q is not None), remove_none_values(params) ) return cast(Map, dict(map._mapping)) if map is not None else None diff --git a/app/repositories/scores.py b/app/repositories/scores.py index ac9fee0d..731d4e20 100644 --- a/app/repositories/scores.py +++ b/app/repositories/scores.py @@ -9,6 +9,7 @@ import app.state.services from app._typing import _UnsetSentinel from app._typing import UNSET +from app.utils import remove_none_values # +-----------------+-----------------+------+-----+---------+----------------+ # | Field | Type | Null | Key | Default | Extra | @@ -239,7 +240,7 @@ async def fetch_many( } recs = await app.state.services.database.fetch_all( - " ".join(q for q in queries if q is not None), params + " ".join(q for q in queries if q is not None), remove_none_values(params) ) return cast(list[Score], [dict(r._mapping) for r in recs]) diff --git a/app/utils.py b/app/utils.py index cdcb9459..77ef4624 100644 --- a/app/utils.py +++ b/app/utils.py @@ -430,3 +430,10 @@ def has_png_headers_and_trailers(data_view: memoryview) -> bool: data_view[:8] == b"\x89PNG\r\n\x1a\n" and data_view[-8:] == b"\x49END\xae\x42\x60\x82" ) + + +def remove_none_values(input_dict: dict[str, T | None]) -> dict[str, T]: + filtered_dict = { + key: value for key, value in input_dict.items() if value is not None + } + return filtered_dict