{{{
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.
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>
* 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>
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>
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>
* owner: nobody => Parth Verma
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:7>
* owner: Parth Verma => evananyonga
--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:8>
* 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>
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>
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>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34818#comment:12>
* 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>