{{{
class Field(**kwargs)
}}}
with no stated constraints on `kwargs`, thus implying (incorrectly) that
any keyword argument can safely be passed to the `forms.Field`
constructor.
That leads to code which worked in previous Django versions but regresses
in the current version. The case I have in mind is
[https://github.com/jezdez/django-
authority/blob/11461f808160e09bb992f9c602c342718892bb6a/authority/admin.py#L28-L33
in django-authority's admin.py] where the `kwargs` passed to
`formfield_callback` (which can include `request`) are passed on to
`Field.formfield`, whose documentation says “All of the `kwargs`
dictionary is passed directly to the form field’s `__init__()` method” ...
and that `__init__` method ''can't'' include `request`. So upgrading
Django yields this somewhat tricky-to-troubleshoot error in a django-
authority admin action:
{{{
TypeError: __init__() got an unexpected keyword argument 'request'
...
File "django/forms/models.py", line 170, in fields_for_model
formfield = formfield_callback(f, **kwargs)
File "authority/admin.py", line 33, in formfield_for_dbfield
return db_field.formfield(**kwargs)
File "django/db/models/fields/__init__.py", line 646, in formfield
return super(CharField, self).formfield(**defaults)
File "django/db/models/fields/__init__.py", line 499, in formfield
return form_class(**defaults)
File "django/forms/fields.py", line 188, in __init__
super(CharField, self).__init__(*args, **kwargs)
}}}
At some point in this chain, the `request` keyword argument must be popped
out. Presumably directly before the call to `Field.formfield`. In any
case, this requirement should be documented.
(Or `forms.Field.__init__` could be changed to tolerate and ignore unknown
keyword arguments. But that's a riskier change.)
--
Ticket URL: <https://code.djangoproject.com/ticket/20744>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/20744#comment:1>
* cc: Pashkin (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/20744#comment:2>