[Django] #34818: GenericIPAddressField ValidationError incorrect message when both protocols present

13 views
Skip to first unread message

Django

unread,
Sep 7, 2023, 10:03:39 AM9/7/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------------+------------------------
Reporter: minusf | Owner: (none)
Type: Bug | Status: new
Component: Error reporting | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
It seems that the `invalid` code for `GenericIPAddressField` models gets
clobbered when both protocols are present in a model:

{{{
class Site(models.Model):
ipv6 = models.GenericIPAddressField(protocol="IPv6")
ipv4 = models.GenericIPAddressField(protocol="IPv4")
}}}

{{{
>>> site = Site(ipv6="6", ipv4="4")
>>> site.full_clean()
raceback (most recent call last):
File "<console>", line 1, in <module>
File "/src/tmp/ip_bug/venv/lib/python3.10/site-
packages/django/db/models/base.py", line 1502, in full_clean
raise ValidationError(errors)
django.core.exceptions.ValidationError: {'ipv6': ['Enter a valid IPv4
address.'], 'ipv4': ['Enter a valid IPv4 address.']}
}}}
sometimes the other message wins:
{{{
ValidationError: {'ipv6': ['Enter a valid IPv6 address.'], 'ipv4': ['Enter
a valid IPv6 address.']}
}}}

p.s. not sure about the component, perhaps could be "Database Layer:
Models" or "Error reporting"?

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

Django

unread,
Sep 7, 2023, 10:04:32 AM9/7/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
---------------------------------+--------------------------------------

Reporter: minusf | Owner: (none)
Type: Bug | Status: new
Component: Error reporting | Version: 4.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by minusf:

Old description:

> It seems that the `invalid` code for `GenericIPAddressField` models gets
> clobbered when both protocols are present in a model:
>
> {{{
> class Site(models.Model):
> ipv6 = models.GenericIPAddressField(protocol="IPv6")
> ipv4 = models.GenericIPAddressField(protocol="IPv4")
> }}}
>
> {{{
> >>> site = Site(ipv6="6", ipv4="4")
> >>> site.full_clean()
> raceback (most recent call last):
> File "<console>", line 1, in <module>
> File "/src/tmp/ip_bug/venv/lib/python3.10/site-
> packages/django/db/models/base.py", line 1502, in full_clean
> raise ValidationError(errors)
> django.core.exceptions.ValidationError: {'ipv6': ['Enter a valid IPv4
> address.'], 'ipv4': ['Enter a valid IPv4 address.']}
> }}}
> sometimes the other message wins:
> {{{
> ValidationError: {'ipv6': ['Enter a valid IPv6 address.'], 'ipv4':
> ['Enter a valid IPv6 address.']}
> }}}
>
> p.s. not sure about the component, perhaps could be "Database Layer:
> Models" or "Error reporting"?

New description:

It seems that the `invalid` code for `GenericIPAddressField` models gets
clobbered when both protocols are present in a model:

{{{
class Site(models.Model):
ipv6 = models.GenericIPAddressField(protocol="IPv6")
ipv4 = models.GenericIPAddressField(protocol="IPv4")
}}}

{{{
>>> site = Site(ipv6="6", ipv4="4")
>>> site.full_clean()

Traceback (most recent call last):


File "<console>", line 1, in <module>
File "/src/tmp/ip_bug/venv/lib/python3.10/site-
packages/django/db/models/base.py", line 1502, in full_clean
raise ValidationError(errors)
django.core.exceptions.ValidationError: {'ipv6': ['Enter a valid IPv4
address.'], 'ipv4': ['Enter a valid IPv4 address.']}
}}}
sometimes the other message wins:
{{{
ValidationError: {'ipv6': ['Enter a valid IPv6 address.'], 'ipv4': ['Enter
a valid IPv6 address.']}
}}}

p.s. not sure about the component, perhaps could be "Database Layer:
Models" or "Error reporting"?

--

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

Django

unread,
Sep 7, 2023, 10:57:31 AM9/7/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* owner: (none) => nobody
* component: Error reporting => Database layer (models, ORM)
* stage: Unreviewed => Accepted


Comment:

Looks like a long-standing bug. A classic error where a class attribute is
shared and modified by different instances. Thanks for the report.

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

Django

unread,
Sep 7, 2023, 4:44:52 PM9/7/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jay Prasad):

Hi! This is my first open source contribution attempt! I was able to
recreate the error and find a hacky solution to it. But it involves
deletion of code and as a beginner, I am not too confident in that! I'd
like to take some time and put more efforts to this issue. Any suggestions
would be highly welcome!

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

Django

unread,
Sep 8, 2023, 8:14:13 AM9/8/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Natalia Bidart):

Replying to [comment:3 Jay Prasad]:


> Hi! This is my first open source contribution attempt! I was able to
recreate the error and find a hacky solution to it. But it involves
deletion of code and as a beginner, I am not too confident in that! I'd
like to take some time and put more efforts to this issue. Any suggestions
would be highly welcome!

Hello Jay, thanks for your contribution! Do you have a PR with your fix?

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

Django

unread,
Sep 24, 2023, 3:14:29 AM9/24/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma
Type: Bug | Status: assigned

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Parth Verma):

* owner: nobody => Parth Verma
* status: new => assigned


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

Django

unread,
Sep 24, 2023, 5:44:05 AM9/24/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Parth Verma):

* has_patch: 0 => 1


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

Django

unread,
Sep 26, 2023, 3:25:19 AM9/26/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


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

Django

unread,
Nov 23, 2023, 3:22:51 PM11/23/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner:
| evananyonga

Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: Parth Verma => evananyonga


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

Django

unread,
Nov 23, 2023, 3:28:21 PM11/23/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma

Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Parth Verma):

* owner: evananyonga => Parth Verma


Comment:

Hi
I was working on the bug fix and had pushed a patch. I was waiting on the
approval on the direction of the fix to finalize the patch. Having
received it just this week I’d like to be reassigned to this so that I can
take this to completion

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

Django

unread,
Nov 23, 2023, 3:36:17 PM11/23/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:9 Parth Verma]:


> Hi
> I was working on the bug fix and had pushed a patch. I was waiting on
the approval on the direction of the fix to finalize the patch. Having
received it just this week I’d like to be reassigned to this so that I can
take this to completion

I left a
[https://github.com/django/django/pull/17305#issuecomment-1750472706
comment] without any reply from you almost 2 months ago.

--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:10>

Django

unread,
Nov 23, 2023, 3:38:08 PM11/23/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Parth Verma):

I thought that comment was for claudep. Anyway, sorry for the confusion.
I’ll raise the final patch this weekend

--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:11>

Django

unread,
Nov 23, 2023, 11:40:25 PM11/23/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

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

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

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:12>

Django

unread,
Nov 23, 2023, 11:46:28 PM11/23/23
to django-...@googlegroups.com
#34818: GenericIPAddressField ValidationError incorrect message when both protocols
present
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: Parth
| Verma
Type: Bug | Status: closed

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"eabfa2d0e38670365aa74117ad2f8710b81065c5" eabfa2d]:
{{{
#!CommitTicketReference repository=""
revision="eabfa2d0e38670365aa74117ad2f8710b81065c5"
Fixed #34818 -- Prevented GenericIPAddressField from mutating error
messages.

Co-authored-by: Parth Verma <parth...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:13>

Reply all
Reply to author
Forward
0 new messages