[Django] #28192: Prevent positional arguments on form fields

8 views
Skip to first unread message

Django

unread,
May 11, 2017, 4:06:23 AM5/11/17
to django-...@googlegroups.com
#28192: Prevent positional arguments on form fields
------------------------------------------------+------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
The documentation already indicates `(**kwargs)` for most of form field
signatures. But in practice, this isn't enforced and any positional
`*args` are passed to the `__init__` methods.

I encountered a strange error with some code of mine which was due to some
label passed erroneously as positional parameter:
`distance = DecimalField("SomeLabel", max_digits=6, decimal_places=2)`
("SomeLabel" was passed as max_value, which only crashed when validating
the form with a strange comparison error).

I think that preventing positional parameters (with a lonely `*`) should
avoid this sort of unexpected errors. This might however be backwards
incompatible for previously well-functioning code.

--
Ticket URL: <https://code.djangoproject.com/ticket/28192>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 11, 2017, 9:59:43 AM5/11/17
to django-...@googlegroups.com
#28192: Prevent passing positional arguments to form fields
--------------------------------------+------------------------------------

Reporter: Claude Paroz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


Comment:

I think it's worth trying this -- we can always revert it and consider a
deprecation path if prerelease testing indicates major pain. I don't
recall encountering form fields using positional arguments during my time
working with Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/28192#comment:1>

Django

unread,
May 11, 2017, 2:10:09 PM5/11/17
to django-...@googlegroups.com
#28192: Prevent passing positional arguments to form fields
--------------------------------------+------------------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Claude Paroz):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/8490 PR]

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

Django

unread,
Jun 3, 2017, 10:15:58 AM6/3/17
to django-...@googlegroups.com
#28192: Prevent passing positional arguments to form fields
--------------------------------------+------------------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"8e752d84378c7169ef73a483ffffcba55a08c867" 8e752d84]:
{{{
#!CommitTicketReference repository=""
revision="8e752d84378c7169ef73a483ffffcba55a08c867"
Refs #28192 -- Made MultiValueField/ComboField fields argument required as
documented.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28192#comment:3>

Django

unread,
Jun 3, 2017, 10:18:14 AM6/3/17
to django-...@googlegroups.com
#28192: Prevent passing positional arguments to form fields
--------------------------------------+------------------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"54caca2d34c7cb6807da0a82bcec7b3a679ac104" 54caca2]:
{{{
#!CommitTicketReference repository=""
revision="54caca2d34c7cb6807da0a82bcec7b3a679ac104"
Refs #28192 -- Fixed documentation of ChoiceField choices requirement

Thanks Tim Graham for noticing the issue.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28192#comment:4>

Django

unread,
Jun 3, 2017, 10:20:18 AM6/3/17
to django-...@googlegroups.com
#28192: Prevent passing positional arguments to form fields
--------------------------------------+------------------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"81c3967e554716dbb5c86ebc390fd07389c39c2e" 81c3967e]:
{{{
#!CommitTicketReference repository=""
revision="81c3967e554716dbb5c86ebc390fd07389c39c2e"
[1.11.x] Refs #28192 -- Fixed documentation of ChoiceField choices
requirement

Thanks Tim Graham for noticing the issue.

Backport of 54caca2d34c7cb6807da0a82bcec7b3a679ac104 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28192#comment:5>

Django

unread,
Jun 3, 2017, 10:49:14 AM6/3/17
to django-...@googlegroups.com
#28192: Prevent passing positional arguments to form fields
--------------------------------------+------------------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"43b574007ef5edfe11f3b899fbe0a6fc05c43774" 43b57400]:
{{{
#!CommitTicketReference repository=""
revision="43b574007ef5edfe11f3b899fbe0a6fc05c43774"
Fixed #28192 -- Required passing optional form field args as keyword args.
}}}

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

Reply all
Reply to author
Forward
0 new messages