Opened 14 years ago
Closed 12 years ago
#15754 closed Cleanup/optimization (fixed)
Сalling _media method many times while getting media value
Reported by: | sakkada | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | media_property |
Cc: | sakkada, marcoberi | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
File django.forms.widgets.py, function media_property, subfunction _media:
if hasattr(super(cls, self), 'media'): base = super(cls, self).media else: base = Media()
"media" attribute of class "cls" is created in the metaclass MediaDefiningClass from method "_media" decorated with "property", so when you call hasattr(super(cls, self), 'media'), "_media" also calling (specifics of the "property"). That's why "_media" method (in property) calling many times, and the number of calls is growing exponentially as the number of ancestor classes. To prevent it, exclude 'hasattr' calls from code. Possible solution is
base = getattr(super(cls, self), 'media', None) or Media()
or
try: base = super(cls, self).media except AttributeError: base = Media()
IMHO, first solution better than using try/except.
Attachments (1)
Change History (8)
comment:1 by , 14 years ago
milestone: | 1.3 |
---|---|
Version: | 1.3 → SVN |
comment:2 by , 14 years ago
Cc: | added |
---|
by , 14 years ago
Attachment: | widgets.diff added |
---|
comment:3 by , 14 years ago
Easy pickings: | unset |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 14 years ago
Needs tests: | set |
---|
comment:5 by , 13 years ago
UI/UX: | unset |
---|
comment:6 by , 12 years ago
Cc: | added |
---|
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Change UI/UX from NULL to False.