Skip to content
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

Editing products with mL as units leads to inconsistent behavior with Hungarian locale #12815

Closed
zsoltiNagy opened this issue Aug 26, 2024 · 13 comments · Fixed by #12826
Closed
Assignees
Labels
bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround.

Comments

@zsoltiNagy
Copy link
Contributor

Description

I encountered an issue when changing the unit scale in the admin/products section. This action causes inconsistent behavior when using the Hungarian (hun) locale. The bug is problematic because it affects the accuracy of product information displayed to users in this locale, leading to potential confusion or errors in interpreting product data. I was trying to ensure that product units are correctly scaled and displayed according to local preferences, but the inconsistency prevents achieving this objective effectively.

Expected Behavior

Changing unit scales with ease.

Actual Behaviour

When changing unit scales, the modified product banner gets stuck and displays inconsistent results. Additionally, the units change in an inconsistent manner.

Steps to Reproduce

  1. admin_style_v3 feature is enabled at /admin/feature-toggle/features
  2. locale is set to hungarian (Magyar)
  3. navigate to /admin/products
  4. try to change any products Unit scale, e.g. from ml to mg

Animated Gif/Screenshot

image
)

Workaround

Switching admin_style_v3 off

Severity

bug-s3: a feature is broken but there is a workaround

@RachL
Copy link
Contributor

RachL commented Aug 26, 2024

@zsoltiNagy many thanks for opening this issue. To be able to fix this we need to be able to replicate :can you detail what you mean by inconsistent?

If you change from ml to mg, what do you get as an inconsistent unit?
Can you translate what the error message means?

Do you have this behavior on all products? All enterprises?
Previously, if the error message would not go away it was often because there was a corrupted product.

@zsoltiNagy
Copy link
Contributor Author

@RachL I'll try best to give you a detailed answer!

->If you change from ml to mg, what do you get as an inconsistent unit?
If we edit a product with a milliliter (ml) packaging, after saving it, a message appears indicating that there is a change and we should save again. If we save again, it converts the product from ml to grams (g) and divides its weight by a thousand. For example, instead of 500 ml, it becomes 0.5 g.

->Can you translate what the error message means?
The error message means 1 product modified.

->Do you have this behavior on all products? All enterprises?
So far where it was tested this bug occured. Though only when the admin_style_v3 feature was turned on.

->Previously, if the error message would not go away it was often because there was a corrupted product.
Yes, this behavior creates corrupted products. The save notification banner stays visible indefinitely and displays incorrect information, such as indicating changes for multiple products when only one has been modified, even if there are no cloned instances present.

@filipefurtad0
Copy link
Contributor

Hey @zsoltiNagy ,

Thanks for reporting! I'm trying to reproduce the issue.

try to change any products Unit scale, e.g. from ml to mg

You're trying to change units from mL to mg, so changing from 500 mL you'd like to get 500 mg - do I understand correctly?

The picture you share displays the unit (g) as selected option. So maybe the mg option is not available for selection. Which makes me wonder whether this option is set under Configuration / General settings tab (accessible only as superadmin):

image

I've tested changing units without the mg option selected (as above) for both the legacy and new design and we do get different behavior. I've created three weight products (500 mL) and changed the unit to g, on different sessions (one legacy products page, and the other one - the new products page). The results are different indeed:

image

We can see that there is a different logic working and that variants have different unit_values:

 weight | unit_value | unit_description | display_name | display_as | variant_unit | unit_presentation 
--------+------------+------------------+--------------+------------+--------------+-------------------
   0.00 |        0.5 |                  |              |            | weight       | 0.5g
   0.50 |        500 |                  |              |            | weight       | 500g
   0.00 |        0.5 |                  |              |            | volume       | 500mL
(3 rows)

The third row displays an unchanged 500 mL product / variant. I could not get strange or inconsistent behavior on saving the changes, or noticed corrupt products.

For example, instead of 500 ml, it becomes 0.5 g.

I could only reproduce this for the legacy products page; for the new products page, I got 500 g (as shown on the pics).

Can you comment on these findings and share your configuration? Many thanks again for your help @zsoltiNagy.

@zsoltiNagy
Copy link
Contributor Author

@filipefurtad0 Thanks for the quick reply and the questions. This morning, I had the opportunity to test this issue more thorougly using the hungarian locale. Here is the configuration I use on my local instance:

Screenshot 2024-08-27 at 05 47 24

I realized there are two -probably connected- issues working in tandem, hence the inconsistent behavior that we noticed.
The first is an issue with changing the Unit Scale:
-> The product has a Volume (mL) Unit Scale with 500ml Unit originally
Screenshot 2024-08-27 at 05 57 22

-> I change it to Weight(mg)
Screenshot 2024-08-27 at 05 58 04
-> The Unit is multiplied by 1000
Screenshot 2024-08-27 at 06 01 04

In itself its not a big problem, though combined with the second it can lead to some confusion.
So, the second, probably the main issue:
-> I want to change the Unit for a Product with mL Unit Scale
Screenshot 2024-08-27 at 06 03 24
Screenshot 2024-08-27 at 06 04 15
-> After clicking on saving the changes ("Változások mentése")the Unit Scale changes to Weight (mg) ("Súly (mg)")
Screenshot 2024-08-27 at 06 05 00
-> The unit is changed to the correct amount:
Screenshot 2024-08-27 at 06 06 03
-> The banner on top is stuck and unresponsive, and now if I click on Save changes/"Változtatások mentése" once again, the black banner on the bottom of the screen shows that the changes were saved and the Unit changes to mg.
Screenshot 2024-08-27 at 06 06 48
-> If I have multiple products using "Volume (mL)"/"Űrtartalom (mL)" and I change only ones Unit value, the same Unit Scale change occurs for both and the banner indicates two product change:
Screenshot 2024-08-27 at 06 38 06
-> Also the stucked banner is permanent and unresponsive, even after changing the locale to English and navigating back to the Products page:
Screenshot 2024-08-27 at 06 39 00
-> The only workaround to get rid of the banner is deleting the affected products.

Sorry if the issue description was confusing at first and once again thanks for the quick replies! :)

@zsoltiNagy
Copy link
Contributor Author

Unit Scale/"Mértékegység skála", Unit/"Mértékegység"

@sigmundpetersen sigmundpetersen added the bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround. label Aug 27, 2024
@filipefurtad0
Copy link
Contributor

Hi @zsoltiNagy ,

Thanks for your detailed description. I am not able to test this in a staging server with the HU locale, we'd need to provision it with this setting.

Given this, I was unable to reproduce the issue:

  • changing unit scale from 500 mL to 500 mg works well, we get the expected result
  • changing unit from 500 mL to 100 mL also works without any issues

I think I could test this in a local environment with the hu locale, I'd need to check how to set the default locales there, not sure how. I'll get back to you once I find something new.

@chahmedejaz
Copy link
Collaborator

Hi everyone, I looked into this issue however, I'm not able to reproduce it even with hu locale in the local environment.
The only error I encountered was a 500 error which resulted in updating the product AUD Price (from the previous locale) values to HUF values.
However, I believe the Hungarian prices on the instances would have been in HUF values already so it shouldn't be an issue there. Even if we did, we would have it logged in the Bugsnag which is not the case. Anyhow, I'm investigating further on the code level. Thanks

@filipefurtad0 Please make the following changes in your env files to have the Hungarian config locale working.:

@chahmedejaz
Copy link
Collaborator

@zsoltiNagy - Just a thought:

-> After clicking on saving the changes ("Változások mentése")the Unit Scale changes to Weight (mg) ("Súly (mg)")
-> The unit is changed to the correct amount:

Do you get the success black banner message below for the first attempt?

@filipefurtad0
Copy link
Contributor

Thanks for your help @chahmedejaz , I had forgotten to change openfoodnetwork/.env as well 🙌

This now worked and I can see the bug:

image

Changing units from 500 to 100 changes the unit scale, from mL to g. But actually it seems, that any change - for example, editing the product name - leads to this as well:

image

It seems this occurs only with units mL. Any change made from a any other unit to mL or on a product/variant which has mL as a unit type will trigger a 422 error on the console. Here is a server log for such a change:


Unpermitted parameters: :authenticity_token, :page, :per_page, :search_term, :producer_id, :category_id, :products, :commit. Context: { controller: Admin::ProductsV3Controller, action: bulk_update, request: #<ActionDispatch::Request:0x0000747ab00c5108>, params: {"authenticity_token"=>"G4-SJ05o4l-UdW69RWSzzGGM8IT3rruIu5qvpqEWsoBFfatCLRl8275F1r19Din8PIwji6ULOpX9Imh16n_zFg", "page"=>"1", "per_page"=>"15", "search_term"=>"", "producer_id"=>"", "category_id"=>"", "products"=>{"0"=>{"id"=>"1", "name"=>"products", "sku"=>"", "variant_unit"=>"volume_0,001", "variant_unit_scale"=>"", "variant_unit_with_scale"=>"volume_0,001", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"2", "display_name"=>"", "sku"=>"", "unit_value"=>"100", "unit_description"=>"", "unit_value_with_description"=>"100", "display_as"=>"", "price"=>"0", "on_hand"=>"0", "on_demand"=>"0", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}, "1"=>{"id"=>"2", "name"=>"Tomate Gloriette", "sku"=>"", "variant_unit"=>"weight", "variant_unit_scale"=>"1.0", "variant_unit_with_scale"=>"weight_1", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"3", "display_name"=>"", "sku"=>"", "unit_value"=>"500.0", "unit_description"=>"", "unit_value_with_description"=>"500", "display_as"=>"", "price"=>"0", "on_demand"=>"1", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}}, "commit"=>"Változások mentése", "controller"=>"admin/products_v3", "action"=>"bulk_update"} }
Unpermitted parameter: :unit_value_with_description. Context: { controller: Admin::ProductsV3Controller, action: bulk_update, request: #<ActionDispatch::Request:0x0000747ab00c5108>, params: {"authenticity_token"=>"G4-SJ05o4l-UdW69RWSzzGGM8IT3rruIu5qvpqEWsoBFfatCLRl8275F1r19Din8PIwji6ULOpX9Imh16n_zFg", "page"=>"1", "per_page"=>"15", "search_term"=>"", "producer_id"=>"", "category_id"=>"", "products"=>{"0"=>{"id"=>"1", "name"=>"products", "sku"=>"", "variant_unit"=>"volume_0,001", "variant_unit_scale"=>"", "variant_unit_with_scale"=>"volume_0,001", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"2", "display_name"=>"", "sku"=>"", "unit_value"=>"100", "unit_description"=>"", "unit_value_with_description"=>"100", "display_as"=>"", "price"=>"0", "on_hand"=>"0", "on_demand"=>"0", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}, "1"=>{"id"=>"2", "name"=>"Tomate Gloriette", "sku"=>"", "variant_unit"=>"weight", "variant_unit_scale"=>"1.0", "variant_unit_with_scale"=>"weight_1", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"3", "display_name"=>"", "sku"=>"", "unit_value"=>"500.0", "unit_description"=>"", "unit_value_with_description"=>"500", "display_as"=>"", "price"=>"0", "on_demand"=>"1", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}}, "commit"=>"Változások mentése", "controller"=>"admin/products_v3", "action"=>"bulk_update"} }
Unpermitted parameter: :unit_value_with_description. Context: { controller: Admin::ProductsV3Controller, action: bulk_update, request: #<ActionDispatch::Request:0x0000747ab00c5108>, params: {"authenticity_token"=>"G4-SJ05o4l-UdW69RWSzzGGM8IT3rruIu5qvpqEWsoBFfatCLRl8275F1r19Din8PIwji6ULOpX9Imh16n_zFg", "page"=>"1", "per_page"=>"15", "search_term"=>"", "producer_id"=>"", "category_id"=>"", "products"=>{"0"=>{"id"=>"1", "name"=>"products", "sku"=>"", "variant_unit"=>"volume_0,001", "variant_unit_scale"=>"", "variant_unit_with_scale"=>"volume_0,001", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"2", "display_name"=>"", "sku"=>"", "unit_value"=>"100", "unit_description"=>"", "unit_value_with_description"=>"100", "display_as"=>"", "price"=>"0", "on_hand"=>"0", "on_demand"=>"0", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}, "1"=>{"id"=>"2", "name"=>"Tomate Gloriette", "sku"=>"", "variant_unit"=>"weight", "variant_unit_scale"=>"1.0", "variant_unit_with_scale"=>"weight_1", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"3", "display_name"=>"", "sku"=>"", "unit_value"=>"500.0", "unit_description"=>"", "unit_value_with_description"=>"500", "display_as"=>"", "price"=>"0", "on_demand"=>"1", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}}, "commit"=>"Változások mentése", "controller"=>"admin/products_v3", "action"=>"bulk_update"} }
Unpermitted parameters: :authenticity_token, :page, :per_page, :search_term, :producer_id, :category_id, :commit. Context: { controller: Admin::ProductsV3Controller, action: bulk_update, request: #<ActionDispatch::Request:0x0000747ab00c5108>, params: {"authenticity_token"=>"G4-SJ05o4l-UdW69RWSzzGGM8IT3rruIu5qvpqEWsoBFfatCLRl8275F1r19Din8PIwji6ULOpX9Imh16n_zFg", "page"=>"1", "per_page"=>"15", "search_term"=>"", "producer_id"=>"", "category_id"=>"", "products"=>{"0"=>{"id"=>"1", "name"=>"products", "sku"=>"", "variant_unit"=>"volume_0,001", "variant_unit_scale"=>"", "variant_unit_with_scale"=>"volume_0,001", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"2", "display_name"=>"", "sku"=>"", "unit_value"=>"100", "unit_description"=>"", "unit_value_with_description"=>"100", "display_as"=>"", "price"=>"0", "on_hand"=>"0", "on_demand"=>"0", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}, "1"=>{"id"=>"2", "name"=>"Tomate Gloriette", "sku"=>"", "variant_unit"=>"weight", "variant_unit_scale"=>"1.0", "variant_unit_with_scale"=>"weight_1", "variant_unit_name"=>"", "variants_attributes"=>{"0"=>{"id"=>"3", "display_name"=>"", "sku"=>"", "unit_value"=>"500.0", "unit_description"=>"", "unit_value_with_description"=>"500", "display_as"=>"", "price"=>"0", "on_demand"=>"1", "supplier_id"=>"1", "primary_taxon_id"=>"1", "tax_category_id"=>"1"}}}}, "commit"=>"Változások mentése", "controller"=>"admin/products_v3", "action"=>"bulk_update"} }

@chahmedejaz chahmedejaz self-assigned this Aug 27, 2024
@chahmedejaz
Copy link
Collaborator

Thanks @filipefurtad0, @zsoltiNagy - I've also reproduced the issue, seems like I was also missing a step. Working on its fix. Thanks

@RachL
Copy link
Contributor

RachL commented Aug 28, 2024

Well done for finding this! I guess this makes it more of an s2? But anyway I see you're on it Ahmed, so probably the severity doesn't change anything at this stage :)

@RachL RachL changed the title Changing the unit scale under admin/products leads to inconsistent behavior with the Hungarian locale Editing products with mL as units leads to to inconsistent behavior Aug 28, 2024
@RachL RachL added bug-s2 The bug is affecting any of the non-critical features described in S1 and there is no workaround. and removed bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround. labels Aug 28, 2024
@chahmedejaz chahmedejaz changed the title Editing products with mL as units leads to to inconsistent behavior Editing products with mL as units leads to inconsistent behavior with Hungarian locale Aug 28, 2024
@chahmedejaz
Copy link
Collaborator

chahmedejaz commented Aug 28, 2024

Sounds right, Rachel. It's only the issue with Hungarian locale, I've found the root cause for this one and will propose the solutions in a while. Thanks

@chahmedejaz
Copy link
Collaborator

chahmedejaz commented Aug 28, 2024

The fix is ready for review and the solutions have been discussed in the PR.
@openfoodfoundation/core-devs would love to hear your thoughts on the fix. As it's creating buggy data on the Hungarian instance, Please let me know if you think of the otherwise solution so that we can fix it before re-drafting the release. Thanks.

@RachL RachL added bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround. and removed bug-s2 The bug is affecting any of the non-critical features described in S1 and there is no workaround. labels Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround.
Projects
Status: Done
5 participants