Skip to content
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

Make Decimal type return None if parsing an empty string #1360

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions graphene/types/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def parse_literal(cls, node):

@staticmethod
def parse_value(value):
if value == "":
return None
try:
return _Decimal(value)
except ValueError:
Expand Down
7 changes: 7 additions & 0 deletions graphene/types/tests/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ def test_decimal_string_query_integer():
assert not result.errors
assert result.data == {"decimal": str(decimal_value)}
assert decimal.Decimal(result.data["decimal"]) == decimal_value

def test_parse_decimal_empty_string():
"""Parsing an empty string should return None"""
result = schema.execute("""{ decimal(input: \"\") }""")
assert not result.errors
assert result.data == {"decimal": None}