Opened 9 years ago
Closed 8 years ago
#28192 closed Cleanup/optimization (fixed)
Prevent passing positional arguments to form fields
| Reported by: | Claude Paroz | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (6)
comment:1 by , 9 years ago
| Summary: | Prevent positional arguments on form fields → Prevent passing positional arguments to form fields |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
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.