#13095 closed (fixed)
modelform_factory, modelformset_factory, inlineformset_factory formfield_callback lambda function missing **kwargs
Reported by: | Harro | Owned by: | Carl Meyer |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | inlineformset_factory sprintSep2010 | |
Cc: | shaun@…, francois@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using the inlineformset_factory with a custom modelform class which has the widgets dict defined in the meta class for one of the fields I ran into the following error.
<lambda>() got an unexpected keyword argument 'widget'
Some debugging later I discovered the formfield_callback definition for the inlineformset_factory is missing the kwargs argument.
Attachments (4)
Change History (21)
by , 15 years ago
Attachment: | ticket13095_r12761.diff added |
---|
comment:1 by , 15 years ago
Needs tests: | set |
---|
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 15 years ago
Attachment: | ticket13095_r13294.diff added |
---|
Updated patch, also fixes modelform_factory and modelformset_factory. Adds tests. Removes encoding problems of previous attempt.
comment:4 by , 15 years ago
Needs tests: | unset |
---|---|
Summary: | inlineformset_factory formfield_callback lamba function missing **kwargs → modelform_factory, modelformset_factory, inlineformset_factory formfield_callback lamba function missing **kwargs |
comment:5 by , 15 years ago
I've tested devinj's patch, the regression test fails without the fix, it succeeds with the fix.
From my own code I can confirm that the patch works.
comment:6 by , 15 years ago
Ok is not critical for 1.2,
but which is the best solution to have a workaround?
We cannot use the Meta widgets = {} in the form...
Ok, we can override the init method and override the widget.
comment:7 by , 14 years ago
I'll probably end up fixing this as part of #13633, since there will be some overlap (especially when it comes to adding tests)
comment:8 by , 14 years ago
Cc: | added |
---|
comment:9 by , 14 years ago
#13633 has been closed wontfix, so this problem needs to be solved on its own. @kenth provided another patch on that ticket.
follow-up: 11 comment:10 by , 14 years ago
I get an error when I try to apply the patch
patch --dry-run -p1 < ~/Downloads/ticket13095_r12761.diff patching file forms/models.py Hunk #1 FAILED at 797. 1 out of 1 hunk FAILED -- saving rejects to file forms/models.py.rej
Any ideas?
comment:11 by , 14 years ago
Replying to jk:
I get an error when I try to apply the patch
patch --dry-run -p1 < ~/Downloads/ticket13095_r12761.diff patching file forms/models.py Hunk #1 FAILED at 797. 1 out of 1 hunk FAILED -- saving rejects to file forms/models.py.rejAny ideas?
My apologies.
I tried applying the patch "ticket13095_r13307.diff" and it worked. It did complain about the missing test files, which I skipped.
by , 14 years ago
Attachment: | 13095-formfield_callback-r13517.diff added |
---|
Use None as default value for formfield_callback (patch from #13633+tests)
comment:12 by , 14 years ago
Having None
as default for formfield_callback
seems better to me, so I added some tests to the patch provided by @kenth in #13633.
The patch is a bit different, though. If formfield_callback
is None
, then formfield()
is called directly instead of creating a lambda that calls it.
Note that not all tests fail before the patch; some of them are there to ensure that changing the defaults to None doesn't change current behaviour.
comment:13 by , 14 years ago
Cc: | added |
---|
comment:14 by , 14 years ago
Keywords: | sprintSep2010 added |
---|---|
Owner: | changed from | to
Summary: | modelform_factory, modelformset_factory, inlineformset_factory formfield_callback lamba function missing **kwargs → modelform_factory, modelformset_factory, inlineformset_factory formfield_callback lambda function missing **kwargs |
Triage Stage: | Accepted → Ready for checkin |
Verified that the latest patch (from vung) applies cleanly, fixes the reported problem, improves code maintainability (the same non-trivial default should not be repeated several different places, or we're asking for this bug to come back for a repeat visit), and adds useful test coverage (I verified that messing with any of the formfield_callback defaults now causes at least one test failure).
Entire test suite passes with the patch (tested only on sqlite, but it's not an ORM patch).
Marking ready-for-checkin. (Feel free to slap me if this is overstepping things).
comment:15 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Bug in inlineformset_factory patch