-
-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: avoid crash if ingredients services called without ingredients_lc #11055
base: main
Are you sure you want to change the base?
Conversation
lib/ProductOpener/Ingredients.pm
Outdated
@@ -1604,7 +1604,7 @@ Array of specific ingredients. | |||
|
|||
sub parse_origins_from_text ($product_ref, $text) { | |||
|
|||
my $ingredients_lc = $product_ref->{ingredients_lc} || $product_ref->{lc}; | |||
my $ingredients_lc = $product_ref->{ingredients_lc} || $product_ref->{lc} || $product_ref->{lang}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where, if we add an Object approach, we could have a method for that on product. (would also work to define a sub get_product_lang)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm refactoring it
lib/ProductOpener/Ingredients.pm
Outdated
@@ -1766,15 +1766,24 @@ sub parse_ingredients_text_service ($product_ref, $updated_product_fields_ref) { | |||
# and indicate that the service is creating the "ingredients" structure | |||
$updated_product_fields_ref->{ingredients} = 1; | |||
|
|||
return if ((not defined $product_ref->{ingredients_text}) or ($product_ref->{ingredients_text} eq "")); | |||
# $product_ref->{ingredients_lc} is defined in extract_ingredients_from_text() | |||
my $ingredients_lc = $product_ref->{ingredients_lc} || $product_ref->{lc} || $product_ref->{lang}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we document this ingredients_lc property (I wasn't aware of it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is in the OpenAPI spec:
ingredients_lc:
type: string
description: |
Language that was used to parse the ingredient list. If `ingredients_text` is available
for the product main language (`lang`), `ingredients_lc=lang`, otherwise we look at
`ingredients_text` fields for other languages and set `ingredients_lc` to the first
non-empty `ingredient_text`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't you add a test for this scenario ?
Quality Gate passedIssues Measures |
@alexgarel Thank you for the feedback. I refactored some things, and then that led to refactoring more things:
|
fixes #11047
In the future, it would be a good thing to enable the services to add error messages that could be returned to the caller, when there is missing data for instance.