Skip to content

Commit

Permalink
fix: add a validator to parse image sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Nov 14, 2024
1 parent 309b4f7 commit 9dd2530
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion openfoodfacts_exports/exports/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class Image(BaseModel):
"""`Images` schema for postprocessing used for field postprocessing."""

key: str | None = None
sizes: dict[str, ImageSize | None]
sizes: dict[str, ImageSize] | None = None
uploaded_t: int | None = None
imgid: int | None = None
uploader: str | None = None
Expand All @@ -240,6 +240,15 @@ def ignore_extra_sizes(self):
}
return self

@model_validator(mode="before")
@classmethod
def parse_sizes(cls, data: dict) -> dict:
sizes = data.pop("sizes", None)
if sizes:
sizes = {key: values for key, values in sizes.items() if values}
data["sizes"] = sizes or None
return data


class Ingredient(BaseModel):
percent_max: float | None = None
Expand Down

0 comments on commit 9dd2530

Please sign in to comment.