From 148349f0f39bcf3a45a084e935ca3d4b116f275f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 17 Jun 2021 12:46:08 +0100 Subject: [PATCH] Ignore potential error where default tax rate is nil If the current tax rates are badly *misconfigured*, and an included-tax rate is being applied but a *default* rate does not exist (there are validations to stop this case from occurring, see DefaultTaxZoneValidator), this line can throw an error. This situation will not actually arise in production, but can happen fairly easily in dev or with staging data when switching datasets, and when it does it's kind of annoying. Note: the logic in the check here is still good; if there's no default tax rate we check if the order's tax zone matches the zone for the current tax rate, which is correct. --- app/models/spree/tax_rate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/tax_rate.rb b/app/models/spree/tax_rate.rb index 369aabb3bf..d86b3d8ca7 100644 --- a/app/models/spree/tax_rate.rb +++ b/app/models/spree/tax_rate.rb @@ -114,7 +114,7 @@ module Spree end def default_zone_or_zone_match?(order) - Zone.default_tax.contains?(order.tax_zone) || order.tax_zone == zone + Zone.default_tax&.contains?(order.tax_zone) || order.tax_zone == zone end # Manually apply a TaxRate to a particular amount. TaxRates normally compute against