Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Apply code review suggestions - update validate_price_amount validator
IKarbowiak9640fb86440e
diff --git a/saleor/graphql/core/validators.py b/saleor/graphql/core/validators.pyindex b6b37c3aa1..4a4ab62650 100644--- a/saleor/graphql/core/validators.py+++ b/saleor/graphql/core/validators.py@@ -1,4 +1,4 @@-from typing import TYPE_CHECKING+from typing import TYPE_CHECKING, Optionalfrom django.conf import settingsfrom django.core.exceptions import ValidationError@@ -20,18 +20,18 @@ def validate_one_of_args_is_in_query(arg1_name, arg1, arg2_name, arg2):)-def validate_price_amount(value: "Decimal", currency: str = None):+def validate_price_amount(value: Optional["Decimal"], currency: str = None):"""Validate if price amount does not have too many decimal places.Price amount can't have more decimal places than currency allow to.+ Works only with decimal created from a string."""+ # check no needed when there is no valueif not value:return- if currency:- currency_fraction = get_currency_fraction(currency)- else:- currency_fraction = get_currency_fraction(settings.DEFAULT_CURRENCY)++ currency_fraction = get_currency_fraction(currency or settings.DEFAULT_CURRENCY)value = value.normalize()if abs(value.as_tuple().exponent) > currency_fraction:raise ValidationError(