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.
* cc: timograham@… (added)
* needs_better_patch: => 0
* component: Uncategorized => Forms
* needs_tests: => 1
* easy: 0 => 1
* needs_docs: => 0
* has_patch: 0 => 1
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Could you add a test for this?
--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:1>
Comment (by Jeff250):
Sure, I've just attached a patch including tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"f2cb94f1c0dc98663e7d493411bf9b82d1894559"]:
{{{
#!CommitTicketReference repository=""
revision="f2cb94f1c0dc98663e7d493411bf9b82d1894559"
Fixed #20740 -- GenericIPAddressField should pass protocol to formfield()
Thanks Jeff250.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:3>
Comment (by Tim Graham <timograham@…>):
In [changeset:"45fab74561a2b339cde922c196ab3ccf998bad10"]:
{{{
#!CommitTicketReference repository=""
revision="45fab74561a2b339cde922c196ab3ccf998bad10"
[1.6.x] Fixed #20740 -- GenericIPAddressField should pass protocol to
formfield()
Thanks Jeff250.
Backport of f2cb94f1c0 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:4>
Comment (by Jeff250):
Tim, the 1.6.x backport isn't quite right, since the 1.6.x constructor
doesn't already set self.protocol. I've attached a trivial patch against
1.6.x that should fix it.
--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:5>
Comment (by timo):
Thanks Jeff.
--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:6>