﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15754	Сalling _media method many times while getting media value	sakkada	nobody	"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."	Cleanup/optimization	closed	Forms	dev	Normal	fixed	media_property	sakkada marcoberi	Accepted	1	0	1	0	0	0
