[Django] #20740: GenericIPAddressField gives misleading error in ModelForm

58 views
Skip to first unread message

Django

unread,
Jul 12, 2013, 1:56:12 AM7/12/13
to django-...@googlegroups.com
#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.

Django

unread,
Jul 12, 2013, 5:01:24 AM7/12/13
to django-...@googlegroups.com
#20740: GenericIPAddressField does not pass protocol to formfield()
-------------------------+------------------------------------
Reporter: Jeff250 | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------+------------------------------------
Changes (by timo):

* 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>

Django

unread,
Jul 12, 2013, 2:37:59 PM7/12/13
to django-...@googlegroups.com
#20740: GenericIPAddressField does not pass protocol to formfield()
-------------------------+------------------------------------
Reporter: Jeff250 | Owner: nobody

Type: Bug | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------+------------------------------------

Comment (by Jeff250):

Sure, I've just attached a patch including tests.

--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:2>

Django

unread,
Jul 12, 2013, 4:06:38 PM7/12/13
to django-...@googlegroups.com
#20740: GenericIPAddressField does not pass protocol to formfield()
-------------------------+------------------------------------
Reporter: Jeff250 | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Jul 12, 2013, 4:06:59 PM7/12/13
to django-...@googlegroups.com
#20740: GenericIPAddressField does not pass protocol to formfield()
-------------------------+------------------------------------
Reporter: Jeff250 | Owner: nobody

Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------+------------------------------------

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>

Django

unread,
Jul 12, 2013, 5:08:27 PM7/12/13
to django-...@googlegroups.com
#20740: GenericIPAddressField does not pass protocol to formfield()
-------------------------+------------------------------------
Reporter: Jeff250 | Owner: nobody

Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------+------------------------------------

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>

Django

unread,
Jul 12, 2013, 6:02:05 PM7/12/13
to django-...@googlegroups.com
#20740: GenericIPAddressField does not pass protocol to formfield()
-------------------------+------------------------------------
Reporter: Jeff250 | Owner: nobody

Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------+------------------------------------

Comment (by timo):

Thanks Jeff.

--
Ticket URL: <https://code.djangoproject.com/ticket/20740#comment:6>

Reply all
Reply to author
Forward
0 new messages