[Django] #25456: GenericIPAddressField does not normalize IPv4 addresses

29 views
Skip to first unread message

Django

unread,
Sep 24, 2015, 3:39:15 AM9/24/15
to django-...@googlegroups.com
#25456: GenericIPAddressField does not normalize IPv4 addresses
-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) | Keywords: ipaddress, ipv4,
Severity: Normal | database, normalization
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
IPv4 addresses do not get normalized before storing them in the database.
They are stored as Char fields in the database which can lead to both
127.0.0.010 and 127.0.0.10 being stored in the database, although the
value should be unique.

--
Ticket URL: <https://code.djangoproject.com/ticket/25456>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 24, 2015, 2:08:57 PM9/24/15
to django-...@googlegroups.com
#25456: GenericIPAddressField does not normalize IPv4 addresses
-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage:
database, normalization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Does the behavior change justify breaking backwards compatibility
(silently changing the input value)? Perhaps so, considering that
PostgreSQL (and its native IP address data type) won't let you store
duplicate values. It reports "Key (ip)=(192.168.1.10) already exists." for
the two addresses you proposed -- so is the proper normalization to remove
the leading zero?

--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:1>

Django

unread,
Sep 25, 2015, 10:05:19 AM9/25/15
to django-...@googlegroups.com
#25456: GenericIPAddressField does not normalize IPv4 addresses
-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage:
database, normalization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by frankvdp):

Replying to [comment:1 timgraham]:


> Does the behavior change justify breaking backwards compatibility
(silently changing the input value)? Perhaps so, considering that
PostgreSQL (and its native IP address data type) won't let you store
duplicate values. It reports "Key (ip)=(192.168.1.10) already exists." for
the two addresses you proposed -- so is the proper normalization to remove
the leading zero?

To start off, I do not really if you're advocating pro or con :-) But, I
think the current situation is pretty bad. I mean, people can create
models with an addresses which they think have unique values. And in a
sense this also goes against what you expect. You expect an generic ip
address object to be evaluated as such, as an ip address, and not as a
mere string value because it is stored as such. As far as I know, there is
also not mention of this in the current documentation.

So, I also don't think that preserving backwards compatibility
preservation is doing anyone a service in this matter. This might leave
people having unreliable data.

--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:2>

Django

unread,
Sep 25, 2015, 10:38:06 AM9/25/15
to django-...@googlegroups.com
#25456: Make GenericIPAddressField normalize IPv4 addresses

-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage: Accepted
database, normalization |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

I was mostly thinking out loud.

--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:3>

Django

unread,
Oct 12, 2015, 1:16:17 AM10/12/15
to django-...@googlegroups.com
#25456: Make GenericIPAddressField normalize IPv4 addresses

-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage: Accepted
database, normalization |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by darjeeling):

I think is it possible to add django.utils.ipv4 ?
for ipv6 normalize, django have **django.utils.ipv6.clean_ipv6_address**.
but I think removing leading zero took about 5~6 lines function.
which namespace is proper to add this function? maybe name will be
**normalize_ipv4_address**

--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:4>

Django

unread,
Oct 12, 2015, 2:38:27 AM10/12/15
to django-...@googlegroups.com
#25456: Make GenericIPAddressField normalize IPv4 addresses

-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage: Accepted
database, normalization |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by darjeeling):

Ok I sent PR. https://github.com/django/django/pull/5424
please check it

--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:5>

Django

unread,
Oct 12, 2015, 5:19:51 AM10/12/15
to django-...@googlegroups.com
#25456: Make GenericIPAddressField normalize IPv4 addresses

-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage: Accepted
database, normalization |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:6>

Django

unread,
Oct 21, 2015, 1:44:23 PM10/21/15
to django-...@googlegroups.com
#25456: Make GenericIPAddressField normalize IPv4 addresses

-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage: Accepted
database, normalization |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:7>

Django

unread,
Feb 2, 2016, 5:04:53 AM2/2/16
to django-...@googlegroups.com
#25456: Make GenericIPAddressField normalize IPv4 addresses

-------------------------------------+-------------------------------------
Reporter: frankvdp | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ipaddress, ipv4, | Triage Stage: Accepted
database, normalization |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sasha0):

* needs_better_patch: 1 => 0
* has_patch: 1 => 0


Comment:

Updated ticket since related PR was closed.

--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:8>

Django

unread,
Jun 25, 2021, 6:55:40 AM6/25/21
to django-...@googlegroups.com
#25456: Make GenericIPAddressField normalize IPv4 addresses
-------------------------------------+-------------------------------------
Reporter: Frank | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: ipaddress, ipv4, | Triage Stage: Accepted
database, normalization |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => fixed


Comment:

Leading zeros are not allowed anymore in IPv4 addresses. Fixed in
e1d787f1b36d13b95187f8f425425ae1b98da188.

--
Ticket URL: <https://code.djangoproject.com/ticket/25456#comment:9>

Reply all
Reply to author
Forward
0 new messages