#20740: GenericIPAddressField gives misleading error in ModelForm
-------------------------------+--------------------
Reporter: Jeff250 | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
If we have a model containing a GenericIPAddressField specifying a
protocol...
{{{
class MyModel(models.Model):
host = models.GenericIPAddressField(protocol='IPv4')
. . .
}}}
And a ModelForm wrapping it...
{{{
class MyForm(forms.ModelForm):
class Meta:
model = models.MyModel
. . .
}}}
Then that form can give a misleading error message after validation. For
instance, with the example above, if you input, e.g., "bletch", you get
the error message "Enter a valid IPv4 or IPv6 address", even though IPv6
addresses are not allowed. (However, if you input, e.g., "::1", you get
the accurate message "Enter a valid IPv4 address".)
It seems like GenericIPAddressField doesn't pass its protocol in its
formfield() method, so the GenericIPAddressField form field first uses a
more general validation rule than the GenericIPAddressField model field.
I'm attaching a patch which fixes this issue in my application.
--
Ticket URL: <https://code.djangoproject.com/ticket/20740>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.1aa03da550010e3abedc7c2a9b1ae506%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.