#26557: GenericIPAddressField no longer normalises empty values to None
----------------------------------------------+--------------------
Reporter: xlq | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
The `GenericIPAddressField` is documented to convert empty strings to
`None` when saving models and when filtering and updating: "If you allow
for blank values, you have to allow for null values since blank values are
stored as null."
#24092 broke this:
{{{
- return value or None
+ return connection.ops.value_to_db_ipaddress(value)
}}}
{{{
+ def value_to_db_ipaddress(self, value):
+ """
+ Transforms a string representation of an IP address into the
expected
+ type for the backend driver.
+ """
+ return value
}}}
The default `value_to_db_ipaddress` function doesn't convert empty strings
to None, like the code it replaced did. This is particularly important
when using a `ModelForm`, since `forms.GenericIPAddressField` sets the
model's field to an empty string if the field is not provided.
--
Ticket URL: <https://code.djangoproject.com/ticket/26557>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/046.831f151e8ffad0016b71f3b526738047%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.