Opened 15 months ago

Last modified 12 months ago

#34818 closed Bug

GenericIPAddressField ValidationError incorrect message when both protocols present — at Version 1

Reported by: minusf Owned by:
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 (1)

comment:1 by minusf, 15 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top