Skip to content

Prevent unknown nutrition values from appearing as zero - #9

Merged
xrpbanks merged 2 commits into
mainfrom
fix/unknown-nutrition-values
Aug 29, 2026
Merged

Prevent unknown nutrition values from appearing as zero#9
xrpbanks merged 2 commits into
mainfrom
fix/unknown-nutrition-values

Conversation

@xrpbanks

Copy link
Copy Markdown
Contributor

Summary

  • stop converting missing, invalid, non-finite, or negative Open Food Facts nutrition values into measured zeroes
  • exclude incomplete records from loggable search results while preserving legitimate measured zero values
  • add a frontend validation boundary and explain that only complete calorie, protein, fat, and carbohydrate records are shown
  • add regression coverage for incomplete nutrition records

Why

A public oats smoke-test returned a product with Nutri-Score B while calories, protein, fat, and carbohydrates were all displayed as 0.0. Missing source data must not be presented as a measured zero in a nutrition-focused product.

Verification completed locally

  • targeted normalization tests: 18 passed
  • full backend suite: 206 passed
  • backend compilation: passed
  • frontend ESLint: passed
  • frontend production build and TypeScript checks: passed
  • Git whitespace check: passed
  • legal/licensing boundary check: passed
  • tracked secret/runtime-artifact boundary: passed

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.

@xrpbanks
xrpbanks marked this pull request as ready for review August 29, 2026 23:17
Copilot AI lite review requested due to automatic review settings August 29, 2026 23:17
@xrpbanks
xrpbanks merged commit 8610e7c into main Aug 29, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_float now returns None for missing/invalid/non-finite/negative inputs, and search_food_products omits 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 {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants