-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Prevent hard-errors when VatPriceGenerator is invoked without a defau… #5324
base: v3.4
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## v3.4 #5324 +/- ##
=======================================
Coverage 86.64% 86.64%
=======================================
Files 580 580
Lines 14741 14743 +2
=======================================
+ Hits 12772 12774 +2
Misses 1969 1969
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I labeled the PR as a breaking change, as it's changing a behavior some people could be relying on. It'll be merged in the next major. |
@@ -46,6 +46,8 @@ def price=(price) | |||
end | |||
|
|||
def net_amount | |||
return nil unless amount |
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 don't believe it's possible for amount
to be nil as of v3.1. (See the "Other important changes" section in the CHANGELOG.md
entry for v3.1, or the PR that removes nil
as a valid value: #3987)
Which means this shouldn't be possible on recent versions of Solidus. (Assuming the task to remove any records with a nil
amount has been run and there isn't any invalid data left in the database from before that change.)
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.
Oops, nevermind. I missed that we were trying to fix a before_validation
callback on Spree::Variant
.
In which case I think the preferred fix should be skipping that callback instead of modifying this public method. The callback already has a conditional associated to it, so I believe it would be a less invasive change to prevent it from running in the case when a price is invalid. (And we avoid any future confusion from having a nil
check in a method where a nil
value is considered invalid.)
Guard against exceptions when calling
Price#net_amount
without a price.Skip trying to calculate foreign prices in
VatPriceGenerator
when thedefault_price
does not have an amount set.Because the
VatPriceGenerator
is invoked in abefore_validate
hook when creating a product, this can lead to exceptions when an admin tries to create a product without specifying a price (and there are non-default countries for which a price needs to be calculated).This PR allows the validations to run without raising exceptions so the admin can see the validation errors.