Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change Decimal implementation to base on the Float
Pacu2e52ce4f15a39
diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.pyindex fb5d8b9785..2d0be908c7 100644--- a/saleor/graphql/core/types/common.py+++ b/saleor/graphql/core/types/common.py@@ -1,37 +1,24 @@import decimalimport graphene-from graphene.types import Scalarfrom graphene_django import DjangoObjectType-from graphql.language import astfrom ....core import weightfrom ..connection import CountableConnection-# FIXME: Decimal scalar implementation has been taken from Graphene repo.-# Remove it when a new version including this implementation is released.-class Decimal(Scalar):+class Decimal(graphene.Float):+ """Custom Decimal implementation.+ Returns Decimal as a float in the API,+ parses float to the Decimal on the way back."""- The `Decimal` scalar type represents a python Decimal.- """-- @staticmethod- def serialize(dec):- if isinstance(dec, str):- dec = decimal.Decimal(dec)- assert isinstance(dec, decimal.Decimal), 'Received not compatible Decimal "{}"'.format(- repr(dec))- return str(dec)-- @classmethod- def parse_literal(cls, node):- if isinstance(node, ast.StringValue):- return cls.parse_value(node.value)@staticmethoddef parse_value(value):try:+ # Converting the float to str before parsing it to Decimal is+ # necessary to keep the decimal places as typed+ value = str(value)return decimal.Decimal(value)except decimal.DecimalException:return None