#34818 closed Bug (fixed)

GenericIPAddressField ValidationError incorrect message when both protocols present

Reported by: minusf Owned by: Parth Verma
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by minusf)

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"?

Change History (13)

comment:1 by minusf, 16 months ago

Description: modified (diff)

comment:2 by Claude Paroz, 16 months ago

Component: Error reportingDatabase layer (models, ORM)
Owner: set to nobody
Triage Stage: UnreviewedAccepted

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

comment:3 by Jay Prasad, 16 months ago

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!

in reply to:  3 comment:4 by Natalia Bidart, 16 months ago

Replying to 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?

comment:5 by Parth Verma, 15 months ago

Owner: changed from nobody to Parth Verma
Status: newassigned

comment:6 by Parth Verma, 15 months ago

Has patch: set

comment:7 by Mariusz Felisiak, 15 months ago

Patch needs improvement: set

comment:8 by Mariusz Felisiak, 13 months ago

Owner: changed from Parth Verma to Eva Nanyonga

comment:9 by Parth Verma, 13 months ago

Owner: changed from Eva Nanyonga to 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

in reply to:  9 comment:10 by Mariusz Felisiak, 13 months ago

Replying to 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 comment without any reply from you almost 2 months ago.

comment:11 by Parth Verma, 13 months ago

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

comment:12 by Mariusz Felisiak, 13 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:13 by GitHub <noreply@…>, 13 months ago

Resolution: fixed
Status: assignedclosed

In eabfa2d:

Fixed #34818 -- Prevented GenericIPAddressField from mutating error messages.

Co-authored-by: Parth Verma <parth.verma@…>

Note: See TracTickets for help on using tickets.
Back to Top