Skip to content

fix: handle None values in ingredients and nutriments to prevent crash#1843

Closed
atheendre130505 wants to merge 2 commits intoopenfoodfacts:mainfrom
atheendre130505:fix/preprocessing-crash
Closed

fix: handle None values in ingredients and nutriments to prevent crash#1843
atheendre130505 wants to merge 2 commits intoopenfoodfacts:mainfrom
atheendre130505:fix/preprocessing-crash

Conversation

@atheendre130505
Copy link

@atheendre130505 atheendre130505 commented Feb 5, 2026

What

handle None values in ingredients and nutriments to prevent crash Fixed a critical crash in generate_inputs_dict within
robotoff/prediction/category/neural/keras_category_classifier_3_0/preprocessing.py.
The crash occurred because product.get(key, default) returns None if the key exists with a None value (common in MongoDB exports), bypassing the intended default empty collections. Implemented the or operator pattern (product.get(key) or default) to ensure None values are correctly handled.
This prevents TypeError: 'NoneType' object is not iterable and AttributeError: 'NoneType' object has no attribute 'get'.
Verified with an exhaustive test suite covering missing keys, explicit None values, and invalid data types.

Screenshot

Test 2: ingredients is None (CRASHES): PASS
Test 5: nutriments is None (CRASHES): PASS
No bug detected - all tests passed as expected

Fixes bug(s)

#1845
Fixes a critical unhandled NoneType crash discovered during codebase analysis in preprocessing.py.

Part of

General stability and error handling improvements for the category predictor model

@raphael0202
Copy link
Collaborator

Hello @atheendre130505,
What issue are you solving here?

@atheendre130505
Copy link
Author

atheendre130505 commented Feb 5, 2026

issue: #1845
@raphael0202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants