Skip to content

Respect allow_null=True on DecimalFields #7718

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

Merged
merged 1 commit into from
Mar 9, 2021

Conversation

kerkeslager
Copy link
Contributor

@kerkeslager kerkeslager commented Feb 16, 2021

Closes #7721

  • Handle None in to_representation()
  • Return None as '' in to_representation() when coerce_to_string=True
  • Handle '' as None in to_internal_value(), for symmetry with
    to_representation(), and because the empty concept doesn't make sense
    for Decimal.

The main fix is the handling of None in to_representation(), but I'm not sure the handling of coerce_to_string makes sense, so I'm definitely open to discussion here.

* Handle None in to_representation()
* Return None as '' in to_representation() when coerce_to_string=True
* Handle '' as None in to_internal_value(), for symmetry with
  to_representation(), and because the empty concept doesn't make sense
  for Decimal.
@kerkeslager
Copy link
Contributor Author

I'm also happy to write docs if I folks agree that the implementation makes sense.

@kerkeslager kerkeslager changed the title Respect allow_null=True on DecimalFields Respect allow_null=True on DecimalFields (Closes #7721) Feb 23, 2021
@kerkeslager kerkeslager changed the title Respect allow_null=True on DecimalFields (Closes #7721) Respect allow_null=True on DecimalFields (Closes encode/django-rest-framework/issues/7721 ) Feb 23, 2021
@kerkeslager kerkeslager changed the title Respect allow_null=True on DecimalFields (Closes encode/django-rest-framework/issues/7721 ) Respect allow_null=True on DecimalFields (Closes encode/django-rest-framework#7721) Feb 23, 2021
@kerkeslager kerkeslager changed the title Respect allow_null=True on DecimalFields (Closes encode/django-rest-framework#7721) Respect allow_null=True on DecimalFields ( closes encode/django-rest-framework#7721 ) Feb 23, 2021
@tomchristie tomchristie changed the title Respect allow_null=True on DecimalFields ( closes encode/django-rest-framework#7721 ) Respect allow_null=True on DecimalFields Mar 9, 2021
@tomchristie
Copy link
Member

This looks good to me, thanks. I don't think we need any extra docs to cover this, the behaviour is more intuitively correct now.

@tomchristie tomchristie merged commit 0551216 into encode:master Mar 9, 2021
stefanacin pushed a commit to stefanacin/django-rest-framework that referenced this pull request Mar 22, 2021
* Handle None in to_representation()
* Return None as '' in to_representation() when coerce_to_string=True
* Handle '' as None in to_internal_value(), for symmetry with
  to_representation(), and because the empty concept doesn't make sense
  for Decimal.
@tomchristie tomchristie mentioned this pull request Mar 25, 2021
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
* Handle None in to_representation()
* Return None as '' in to_representation() when coerce_to_string=True
* Handle '' as None in to_internal_value(), for symmetry with
  to_representation(), and because the empty concept doesn't make sense
  for Decimal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DecimalField errors on serialization of None, even when allow_null=True
2 participants