Opened 10 years ago

Closed 10 years ago

#3534 closed (fixed)

newforms ModelChoiceField should not cache choices

Reported by: Adrian Holovaty Owned by: Adrian Holovaty
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

ModelChoiceField and ModelMultipleChoiceField cache the output of their queryset the first time self.choices is accessed. This is bad for long-running processes, such as mod_python, because the cache gets stale. Plus, it's bad saving all of those choices in memory. The attached unit tests illustrate the problem.

Attachments (1)

model_choice_field_cache_tests.patch (1.1 KB) - added by Adrian Holovaty 10 years ago.
Unit tests

Download all attachments as: .zip

Change History (3)

comment:1 Changed 10 years ago by Adrian Holovaty

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Changed 10 years ago by Adrian Holovaty

Unit tests

comment:2 Changed 10 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [4552]) Fixed #3534 -- newforms ModelChoiceField and ModelMultipleChoiceField no longer cache choices. Instead, they calculate choices via a fresh database query each time the widget is rendered and clean() is called

Note: See TracTickets for help on using tickets.
Back to Top