Skip to content

Commit bd229dc

Browse files
committed
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.
1 parent b3cacec commit bd229dc

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎app/models/smartphone.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Smartphone(SQLModel, table=True):
2929
msrp_usd: int | None = None
3030

3131
# Memory
32-
ram_gb: int
32+
ram_gb: float # sub-GB on 2006-2012 phones (original iPhone 0.125)
3333
storage_options_gb: list[int] = Field(default_factory=list, sa_column=Column(JSON))
3434
variant: dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON))
3535

‎app/schemas/serializers.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
PREFIX = settings.api_version_prefix
3030

3131

32+
def _whole_as_int(value: float) -> int | float:
33+
"""8.0 → 8 so whole-GB phones keep their integer JSON; 0.125 stays a float."""
34+
return int(value) if float(value).is_integer() else value
35+
36+
3237
def url_for(resource: str, slug: str) -> str:
3338
"""Build a versioned resource URL, e.g. ``/v1/smartphones/galaxy-s25``."""
3439
return f"{PREFIX}/{resource}/{slug}"
@@ -250,7 +255,7 @@ def smartphone_read(
250255
soc=soc_summary(soc, soc_manufacturer),
251256
release_date=phone.release_date,
252257
msrp_usd=phone.msrp_usd,
253-
ram_gb=phone.ram_gb,
258+
ram_gb=_whole_as_int(phone.ram_gb),
254259
storage_options_gb=phone.storage_options_gb,
255260
variant=phone.variant,
256261
display=phone.display,

‎app/schemas/smartphone.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SmartphoneRead(BaseModel):
3636
soc: SoCSummary
3737
release_date: date
3838
msrp_usd: int | None = None
39-
ram_gb: int
39+
ram_gb: int | float
4040
storage_options_gb: list[int]
4141
variant: dict[str, Any]
4242
display: dict[str, Any]

0 commit comments

Comments
 (0)