fix: handle None values in ingredients and nutriments to prevent crash#1843
Closed
atheendre130505 wants to merge 2 commits intoopenfoodfacts:mainfrom
Closed
fix: handle None values in ingredients and nutriments to prevent crash#1843atheendre130505 wants to merge 2 commits intoopenfoodfacts:mainfrom
atheendre130505 wants to merge 2 commits intoopenfoodfacts:mainfrom
Conversation
Collaborator
|
Hello @atheendre130505, |
Author
|
issue: #1845 |
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.
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