From 0fdc2ca3eb206c7b7ffd7f160ea4bd314a85a480 Mon Sep 17 00:00:00 2001 From: Mark Chackerian Date: Mon, 16 Jul 2018 17:20:49 -0400 Subject: [PATCH] should fix some import issues with python 2.7 --- graphene/types/decimal.py | 10 +++++++--- graphene/types/tests/test_decimal.py | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/graphene/types/decimal.py b/graphene/types/decimal.py index 29db46b9..1bc07b01 100644 --- a/graphene/types/decimal.py +++ b/graphene/types/decimal.py @@ -1,4 +1,6 @@ -import decimal +from __future__ import absolute_import + +from decimal import Decimal as _Decimal from graphql.language import ast @@ -11,7 +13,9 @@ class Decimal(Scalar): """ @staticmethod def serialize(dec): - assert isinstance(dec, decimal.Decimal), ( + if isinstance(dec, str): + dec = _Decimal(dec) + assert isinstance(dec, _Decimal), ( 'Received not compatible Decimal "{}"'.format(repr(dec)) ) return str(dec) @@ -24,6 +28,6 @@ class Decimal(Scalar): @staticmethod def parse_value(value): try: - return decimal.Decimal(value) + return _Decimal(value) except ValueError: return None diff --git a/graphene/types/tests/test_decimal.py b/graphene/types/tests/test_decimal.py index ac8d2d58..cde048e4 100644 --- a/graphene/types/tests/test_decimal.py +++ b/graphene/types/tests/test_decimal.py @@ -21,6 +21,7 @@ def test_decimal_string_query(): assert result.data == { 'decimal': str(decimal_value) } + assert decimal.Decimal(result.data['decimal']) == decimal_value def test_decimal_string_query_variable(): @@ -34,6 +35,7 @@ def test_decimal_string_query_variable(): assert result.data == { 'decimal': str(decimal_value) } + assert decimal.Decimal(result.data['decimal']) == decimal_value def test_bad_decimal_query():