Opened 6 years ago

Closed 4 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: master
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


File, function media_property, subfunction _media:

if hasattr(super(cls, self), 'media'):
    base = super(cls, self).media
    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()


    base = super(cls, self).media
except AttributeError:
    base = Media()

IMHO, first solution better than using try/except.

Attachments (1)

widgets.diff (634 bytes) - added by sakkada 6 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by sakkada

milestone: 1.3
Version: 1.3SVN

comment:2 Changed 6 years ago by sakkada

Cc: sakkada added

Changed 6 years ago by sakkada

Attachment: widgets.diff added

comment:3 Changed 6 years ago by Jacob

Easy pickings: unset
Triage Stage: UnreviewedAccepted

comment:4 Changed 6 years ago by Julien Phalip

Needs tests: set

comment:5 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 Changed 4 years ago by marcoberi

Cc: marcoberi added

comment:7 Changed 4 years ago by Alex Gaynor <alex.gaynor@…>

Resolution: fixed
Status: newclosed

In [ede49c7ee03dd1519d0c375d953cb73e106837b6]:

Fixed #15754 -- avoid recursively computing the tree of media widgets more times than is necessary for a wiget

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