Why would render() get called multiple times?

127 views
Skip to first unread message

Karen Tracey

unread,
Sep 10, 2008, 4:06:19 PM9/10/08
to django-d...@googlegroups.com
We have this problem that's been seen in the wild by a couple-three people now:

http://code.djangoproject.com/ticket/8110

It apparently results from the AdminLogNode's render() function getting called multiple times, since the patch that protects against that by not modifying self.user in render fixes the issue for the last two people who have reported the problem.  I think that's an OK fix (render() is supposed to allow for being called more than once, right, since if the template tag is in a loop the same node will get rendered multiple times?)...but I can't understand why, in this case, render() is getting called more than once.  The tag is not in any sort of a loop in admin's index.html file (and the reporter says that file has not been modified).  What else might cause render to get called multiple times for the same template node?

A further bit of weirdness is that the problem is reported to only occur with DEBUG set to False.  If deubug is on, no problem.  If it's off, sporadic internal server errors on the main admin page.  I can't recreate it at all, regardless of debug setting or deployment method.  Any ideas?

Karen

Karen Tracey

unread,
Sep 19, 2008, 3:33:21 PM9/19/08
to django-d...@googlegroups.com

Armin's notes on template thread-safety reminded me of this little problem.  If I'm reading his notes correctly, multiple threads re-using the same parsed template object could cause this problem.  But, he also notes that by default templates are parsed and evaluated for each request, so the app would have to do something to cause the same parsed template to be used for multiple requests...and from a quick look I can't see that Admin does anything like that? 

Does anyone have an opinion on whether it would be better to just put the existing fix in as-is, or leave this open for a bit to try to understand why it is happening?

Karen

Malcolm Tredinnick

unread,
Sep 19, 2008, 9:32:50 PM9/19/08
to django-d...@googlegroups.com

On Fri, 2008-09-19 at 15:33 -0400, Karen Tracey wrote:
[...]

>
> Does anyone have an opinion on whether it would be better to just put
> the existing fix in as-is, or leave this open for a bit to try to
> understand why it is happening?

I personally would want to understand what's really going on before
committing anything.

Malcolm

>

Manuel Saelices

unread,
Sep 19, 2008, 11:15:23 PM9/19/08
to Django developers
The reason is that first time self.user is loaded with an user object
and second time is loaded a integer.

Offtopic: Two weeks ago, I tried to optimize template system by
caching compiled templates loaded by Django "loader". The results was
wonderful but in admin site was no working. I had no time to fix
problem but now I've seen #8110 patch and was perfect fix for my
issue. Now I've created a ticket for that optimization hack:

http://code.djangoproject.com/ticket/9154

Regards,
Manuel Saelices

>
> Malcolm
>
>
Reply all
Reply to author
Forward
0 new messages