-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
missing "unit_value" validation when changing from item -> weight on /products/<product_name>/edit #6737
Comments
So I'm seeing different behavior than you @filipefurtad0. When I got to the /edit page for a product using I took a long trip down a rabbit hole to look at what all happens when the units are changed. There's a few methods in Were you able to confirm in the console that the variant's Even if not, I think there's a clear takeaway from this, which is that if a variant's I would propose a data migration to search for any variants where their product is set to use |
This reminds me of the discussion we had around unit prices with @sauloperez & @andrewpbrett , that for when Does #6369 fix only inconsistencies when changing Wondering about the usecase behind: are users commonly creating products with |
Did you create a second variant (step 2.) for that product @andrewpbrett ? Setting the After this, adding this variant to an OC and trying to clone that OC leads to #4216. I had another look, and So, although the solution you propose on #6792 does not introduce validation on the |
I've just noticed a Spree commit which might be related to this: spree/spree#4300 They set variant weight to default to 0.0 at database level, which avoids nil values. Could be relevant/useful? |
Yes, that could be relevant indeed @Matt-Yorkley , The corrupt variants from cases I could reproduce were secondary variants ( |
@Matt-Yorkley good catch. I tacked on a line to #6792 to ensure that weight is also never nil. That PR was ready to go so I'll just do a quick dev test and confirm. |
Another hypothesis is that we are feeding the DBs through our product import feature, with :
I'm not sure But if we enforce control on the DB level, than I guess we are good? Can you confirm that @Matt-Yorkley @andrewpbrett? |
It seems unlikely to me that this would all be coming from product import; I think someone would have mentioned it when asking them what they were doing. But in any case, enforcing it at the DB level would take care of it even if it is coming from a product import. |
After the dev test, I noticed that I could still force a So I added a constraint to check for this at the DB level. I also added a line to the migration to check for any existing variants with |
Description
Product edits made through the path
/products/<product_name>/edit
are not being validated on theunit_value
field. This can corrupt variants, with consequences on the shopfront, product and order cycle pages, as observed in #6527, #4216, #6368 and #5234.Until recently, it was possible to create new variants with
unit_value = 0
. If this variant was from a product which hadvariant_unit = items
and was changed intovariant_unit = weight
then a corrupt variant could be created. However:i) a corrupt variant would not be created if this change was done under through the
/products
page. This pages validates the mandatory fields, and did not allow to create a weight item withunit_value = <empty>
.ii) a corrupt variant would only be created if this change was done under at
/products/<product_name>/edit
As I understand this, PR #6369 prevents variants to be created with an empty
unit_value
. This introduced to prevent this from happening, and automatically introduces a value (1), in these cases.However, if variants from products with
variant_unit = items
were created withunit_value = <empty>
previous to the deployment of #6369 in production, then these can still be changed fromvariant_unit = items
->variant_unit = weight
, via ii), i.e., through/products/<product_name>/edit
where validation for this mandatory field does occur.I think this might explain the reoccurrence from #6527 - ping @Matt-Yorkley @andrewpbrett
Expected Behavior
unit_value
field is not being validated - cannot be empty - when product edits occur via/products/<product_name>/edit
.Actual Behaviour
unit_value
field should be validated - cannot be empty - when product edits occur via/products/<product_name>/edit
.Steps to Reproduce
If you can find a product in staging with
variant_unit = items
and variants with nounit_value
just skip to step 6.variant_unit = items
unit_value
: log in to the server and open the SQL shellSaving failed. Saving failed with the following error(s): Unit value can't be blank
/products/<product_name>/edit
: See that no validation occurs - at this step, the corrupt variant is created - the green banner should displayProduct "<product name>" has been successfully updated!
See testing notes for more details.
Animated Gif/Screenshot
Workaround
Using the
/products
page to change this type of products from items -> weight (not sure this is a workaround).Severity
This would prevent further occurrences from #6527, at least it would prevent some?
taking the liberty to rate this one as an S2 - ping @openfoodfoundation/train-drivers-product-owners
Your Environment
Possible Fix
The text was updated successfully, but these errors were encountered: