Prevent unknown nutrition values from appearing as zero - #9
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents missing/invalid nutrition values from being displayed as measured 0.0 by treating unknown upstream nutrition values as “unknown” and filtering incomplete records out of the UI and backend search results.
Changes:
- Backend:
_to_floatnow returnsNonefor missing/invalid/non-finite/negative inputs, andsearch_food_productsomits products with any unknown macro value. - Frontend: Food item normalization now filters out records missing any of calories/protein/fat/carbohydrates and updates empty-state/help copy accordingly.
- Tests: Adds regression coverage ensuring incomplete Open Food Facts products are excluded from search results and that valid values are preserved.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/components/FoodSearchPlaceholder.tsx | Filters out incomplete nutrition records client-side and updates UI messaging/empty state text. |
| backend/app/services/open_food_facts.py | Treats invalid nutrition as unknown (None) and excludes incomplete upstream products from search results. |
| backend/tests/test_open_food_facts_normalization.py | Adds regression tests for _to_float behavior and search filtering of incomplete products. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -135,13 +137,26 @@ async def search_food_products(query: str, page_size: int = 10) -> list[FoodSear | |||
| continue | |||
|
|
|||
| nutriments = product.get("nutriments") or {} | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
A public
oatssmoke-test returned a product with Nutri-Score B while calories, protein, fat, and carbohydrates were all displayed as0.0. Missing source data must not be presented as a measured zero in a nutrition-focused product.Verification completed locally
Scope and release boundary
This draft PR changes only three files and does not alter authentication, storage, databases, WordPress, Render configuration, social channels, bots, or showcase media.
Do not merge or deploy until the owner reviews this PR. After deployment, repeat the public search and portion-preview smoke-test before closing blocker B26 or publishing the consumer-facing R1 showcase.