Opened 5 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 5 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by sakkada

  • milestone 1.3 deleted
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.3 to SVN

comment:2 Changed 5 years ago by sakkada

  • Cc sakkada added

Changed 5 years ago by sakkada

comment:3 Changed 5 years ago by jacob

  • Easy pickings unset
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 5 years ago by julien

  • Needs tests set

comment:5 Changed 5 years ago by aaugustin

  • 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 set to fixed
  • Status changed from new to closed

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