Solution is to use the "if x not in d" pattern instead of setdefault.
I'll create a pull request.
--
Ticket URL: <https://code.djangoproject.com/ticket/26018>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => chmarr
* needs_docs: => 0
* status: new => assigned
* needs_tests: => 0
* needs_better_patch: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26018#comment:1>
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Pull request: https://github.com/django/django/pull/5900
Release notes for 1.9.1 updated. Docs compile without error. Test case
added. All tests pass under Sqlite.
--
Ticket URL: <https://code.djangoproject.com/ticket/26018#comment:2>
Comment (by chmarr):
Note: I added a call-counter stub to the AuthorUpdate view. Ideally I'd
use the "mock" library to do this kind of thing, as that would also let me
check the call-count after form_valid, rather than only being able to test
if res.context['view'] was present.
--
Ticket URL: <https://code.djangoproject.com/ticket/26018#comment:3>
* stage: Accepted => Ready for checkin
Comment:
Thanks, I'll merge the release note with the one for #25548 since it seems
this issue isn't present in 1.9 but rather introduced in the fix for that
ticket as you mentioned.
By the way, we have automated checks on the pull request for docs building
without error and tests passing, so there's no need to mention all that
here.
--
Ticket URL: <https://code.djangoproject.com/ticket/26018#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e429c5186ceed81c4627165518e0c70c58e69595" e429c51]:
{{{
#!CommitTicketReference repository=""
revision="e429c5186ceed81c4627165518e0c70c58e69595"
Fixed #26018 -- Prevented unecessary get_form() call in
FormMixin.get_context_data().
Changed "dict.setdefault" to "if x in dict" pattern so that get_form()
would not
be called unnecessarily, specifically in the case where
FormMixin.form_invalid()
calls get_context_data() with the current form.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26018#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"8202ce45a5ae5dac2c6fdf94bf3554180bbdd7b7" 8202ce45]:
{{{
#!CommitTicketReference repository=""
revision="8202ce45a5ae5dac2c6fdf94bf3554180bbdd7b7"
[1.9.x] Fixed #26018 -- Prevented unecessary get_form() call in
FormMixin.get_context_data().
Changed "dict.setdefault" to "if x in dict" pattern so that get_form()
would not
be called unnecessarily, specifically in the case where
FormMixin.form_invalid()
calls get_context_data() with the current form.
Backport of e429c5186ceed81c4627165518e0c70c58e69595 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26018#comment:6>