graphene
graphene copied to clipboard
Make Decimal type return None if parsing an empty string
Would fix #927.
When using forms in the frontend, it's often useful for the "null" value of the form field to be an empty string, as HTML Input elements don't take null for a value. When converting that form value into a Graphene Decimal type, an empty string will currently cause a ConversionError. This PR makes empty strings a valid "null" value for Decimal.
Hey @abs25, I'm not a contributor, but I also encountered this issue. I think the issue here is that the original author of Graphene's Decimal type assumed that a ValueError
would be raised in the case of a value that couldn't be parsed. However, that's not the case.
Rather than checking for a blank string, I a better solution would be to change except ValueError
to except decimal.InvalidOperation
. This will handle scenarios where someone sends "abc"
to the server as well.