From bd229dc4d6b6c059388bf11eccf1197a2598e411 Mon Sep 17 00:00:00 2001 From: Seungpyo1007 Date: Fri, 25 Sep 2026 16:22:42 +0900 Subject: [PATCH] Store phone RAM as a float so sub-GB phones can be served TechAPI #257 corrected storage-as-RAM on 2006-2012 phones (original iPhone 0.125 GB). SmartphoneRead.ram_gb was int, so the static dump crashed on those records. Store it as float, type the schema int | float, and emit whole values as ints so the other ~90k pages keep "ram_gb": 8. --- app/models/smartphone.py | 2 +- app/schemas/serializers.py | 7 ++++++- app/schemas/smartphone.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/smartphone.py b/app/models/smartphone.py index e97f0b4..16f6080 100644 --- a/app/models/smartphone.py +++ b/app/models/smartphone.py @@ -29,7 +29,7 @@ class Smartphone(SQLModel, table=True): msrp_usd: int | None = None # Memory - ram_gb: int + ram_gb: float # sub-GB on 2006-2012 phones (original iPhone 0.125) storage_options_gb: list[int] = Field(default_factory=list, sa_column=Column(JSON)) variant: dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON)) diff --git a/app/schemas/serializers.py b/app/schemas/serializers.py index 65e59fd..0cd507f 100644 --- a/app/schemas/serializers.py +++ b/app/schemas/serializers.py @@ -29,6 +29,11 @@ PREFIX = settings.api_version_prefix +def _whole_as_int(value: float) -> int | float: + """8.0 → 8 so whole-GB phones keep their integer JSON; 0.125 stays a float.""" + return int(value) if float(value).is_integer() else value + + def url_for(resource: str, slug: str) -> str: """Build a versioned resource URL, e.g. ``/v1/smartphones/galaxy-s25``.""" return f"{PREFIX}/{resource}/{slug}" @@ -250,7 +255,7 @@ def smartphone_read( soc=soc_summary(soc, soc_manufacturer), release_date=phone.release_date, msrp_usd=phone.msrp_usd, - ram_gb=phone.ram_gb, + ram_gb=_whole_as_int(phone.ram_gb), storage_options_gb=phone.storage_options_gb, variant=phone.variant, display=phone.display, diff --git a/app/schemas/smartphone.py b/app/schemas/smartphone.py index b3df878..938b928 100644 --- a/app/schemas/smartphone.py +++ b/app/schemas/smartphone.py @@ -36,7 +36,7 @@ class SmartphoneRead(BaseModel): soc: SoCSummary release_date: date msrp_usd: int | None = None - ram_gb: int + ram_gb: int | float storage_options_gb: list[int] variant: dict[str, Any] display: dict[str, Any]