Skip to content

Commit

Permalink
Merge pull request #1470 from rommapp/master
Browse files Browse the repository at this point in the history
v3.7.2
  • Loading branch information
gantoine authored Jan 12, 2025
2 parents 2e2707a + 8872161 commit d880e64
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
13 changes: 7 additions & 6 deletions backend/models/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, safe_int

if TYPE_CHECKING:
from models.assets import Save, Screenshot, State
Expand Down Expand Up @@ -165,20 +165,21 @@ 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:
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
)
Expand Down
16 changes: 16 additions & 0 deletions backend/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ 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


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
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d880e64

Please sign in to comment.