From b4b0d3fb8545184a228aa589e6a9b817f40253af Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 11 Jan 2025 19:22:31 -0500 Subject: [PATCH 1/3] [HOTFIX] Safe cast values to float --- backend/models/rom.py | 6 +++--- backend/utils/database.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/models/rom.py b/backend/models/rom.py index cc243e35a..4f88343df 100644 --- a/backend/models/rom.py +++ b/backend/models/rom.py @@ -20,7 +20,7 @@ func, ) from sqlalchemy.orm import Mapped, mapped_column, relationship -from utils.database import CustomJSON +from utils.database import CustomJSON, safe_float if TYPE_CHECKING: from models.assets import Save, Screenshot, State @@ -173,12 +173,12 @@ def first_release_date(self) -> int: @property def average_rating(self) -> float | None: igdb_rating = ( - float(self.igdb_metadata.get("total_rating", 0)) + safe_float(self.igdb_metadata.get("total_rating") or 0) if self.igdb_metadata else 0.0 ) moby_rating = ( - float(self.moby_metadata.get("moby_score", 0)) + safe_float(self.moby_metadata.get("moby_score") or 0) if self.moby_metadata else 0.0 ) diff --git a/backend/utils/database.py b/backend/utils/database.py index e9823111b..14d4641c1 100644 --- a/backend/utils/database.py +++ b/backend/utils/database.py @@ -29,3 +29,11 @@ def json_array_contains_value( func.cast(value, sa_pg.JSONB) ) return func.json_contains(column, value) + + +def safe_float(value, default=0.0): + """Safely convert a value to float, returning default if conversion fails.""" + try: + return float(value) + except (ValueError, TypeError): + return default From 573ec47159cb0c7a7249db1af9a58a3c391d1bb4 Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Sat, 11 Jan 2025 21:20:35 -0300 Subject: [PATCH 2/3] misc: Move to py7zr v1.0.0rc2 Stop using `py7zr` fork and move to `1.0.0rc2` release, which includes decompression streaming support. --- docker/Dockerfile | 2 +- poetry.lock | 18 +++++++----------- pyproject.toml | 4 +--- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 6c43130dd..ad257a4dc 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -30,7 +30,7 @@ RUN npm run build FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} AS backend-build -# git is needed to install py7zr fork +# git is needed to install streaming-form-data fork # libffi-dev is needed to fix poetry dependencies for >= v1.8 on arm64 # libpq-dev is needed to build psycopg-c # mariadb-connector-c-dev is needed to build mariadb-connector diff --git a/poetry.lock b/poetry.lock index ba5c7c5d3..dba2106fa 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1766,12 +1766,14 @@ tests = ["pytest"] [[package]] name = "py7zr" -version = "0.1.dev1828" +version = "1.0.0rc2" description = "Pure python 7-zip library" optional = false python-versions = ">=3.9" -files = [] -develop = false +files = [ + {file = "py7zr-1.0.0rc2-py3-none-any.whl", hash = "sha256:4eba876d6018ccc7aead07d5f10795151be5b272289078b899f199b27d2dae41"}, + {file = "py7zr-1.0.0rc2.tar.gz", hash = "sha256:8a62e7c96050eb357ab5a41a7863078931733e235e796468b4d5e22bb0888bf0"}, +] [package.dependencies] brotli = {version = ">=1.1.0", markers = "platform_python_implementation == \"CPython\""} @@ -1786,18 +1788,12 @@ pyzstd = ">=0.16.1" texttable = "*" [package.extras] -check = ["black (>=24.8.0)", "check-manifest", "flake8 (<8)", "flake8-black (>=0.3.6)", "flake8-deprecated", "flake8-isort", "isort (>=5.13.2)", "lxml", "mypy (>=1.10.0)", "mypy_extensions (>=1.0.0)", "pygments", "readme-renderer", "twine", "types-psutil"] +check = ["black (>=24.8.0)", "check-manifest", "flake8 (<8)", "flake8-black (>=0.3.6)", "flake8-deprecated", "flake8-isort", "isort (>=5.13.2)", "lxml", "mypy (>=1.10.0)", "mypy_extensions (>=1.0.0)", "pygments", "pylint", "readme-renderer", "twine", "types-psutil"] debug = ["pytest", "pytest-leaks", "pytest-profiling"] docs = ["docutils", "sphinx (>=7.0.0)", "sphinx-a4doc", "sphinx-py3doc-enhanced-theme"] test = ["coverage[toml] (>=5.2)", "coveralls (>=2.1.1)", "py-cpuinfo", "pytest", "pytest-benchmark", "pytest-cov", "pytest-httpserver", "pytest-remotedata", "pytest-timeout", "requests"] test-compat = ["libarchive-c"] -[package.source] -type = "git" -url = "https://github.com/adamantike/py7zr.git" -reference = "54b68426" -resolved_reference = "54b68426775988229db657f2c196e5f84b6ff69e" - [[package]] name = "pybcj" version = "1.0.2" @@ -3582,4 +3578,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "5c2a001de459f5cd5586f834cec3607163ec3800a466332b37afeb7b9862219e" +content-hash = "8b0d4ecd3191f13860cbfc3211112bd66966388afdcb31582c8138f9100e9b05" diff --git a/pyproject.toml b/pyproject.toml index 43d49a65f..191660884 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,9 +43,7 @@ pillow = "^10.3.0" certifi = "2024.07.04" authlib = "^1.3.1" python-magic = "^0.4.27" -# TODO: Move back to official releases once the following PR is merged and released: -# https://github.com/miurahr/py7zr/pull/620 -py7zr = { git = "https://github.com/adamantike/py7zr.git", rev = "54b68426" } +py7zr = "1.0.0rc2" sentry-sdk = "^2.19" # TODO: Move back to official releases once the following PR is merged and released: # https://github.com/python-poetry/poetry-core/pull/803 From aacad9c6977fa0309bd1710eda20c4186f59c538 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 11 Jan 2025 19:37:39 -0500 Subject: [PATCH 3/3] [HOTFIX] Safe cast values to int for first_release_date --- backend/models/rom.py | 9 +++++---- backend/utils/database.py | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/models/rom.py b/backend/models/rom.py index 4f88343df..ddf45a801 100644 --- a/backend/models/rom.py +++ b/backend/models/rom.py @@ -20,7 +20,7 @@ func, ) from sqlalchemy.orm import Mapped, mapped_column, relationship -from utils.database import CustomJSON, safe_float +from utils.database import CustomJSON, safe_float, safe_int if TYPE_CHECKING: from models.assets import Save, Screenshot, State @@ -165,10 +165,11 @@ def alternative_names(self) -> list[str]: ) @property - def first_release_date(self) -> int: + def first_release_date(self) -> int | None: if self.igdb_metadata: - return self.igdb_metadata.get("first_release_date", 0) * 1000 - return 0 + return safe_int(self.igdb_metadata.get("first_release_date") or 0) * 1000 + + return None @property def average_rating(self) -> float | None: diff --git a/backend/utils/database.py b/backend/utils/database.py index 14d4641c1..e148fe39c 100644 --- a/backend/utils/database.py +++ b/backend/utils/database.py @@ -37,3 +37,11 @@ def safe_float(value, default=0.0): return float(value) except (ValueError, TypeError): return default + + +def safe_int(value, default=0): + """Safely convert a value to int, returning default if conversion fails.""" + try: + return int(value) + except (ValueError, TypeError): + return default