Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8182 closed (fixed)

infinite loop iterating over context_processors.PermWrapper

Reported by: Uz Owned by:
Component: contrib.auth Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The template code below will cause an infinite memory-eating loop if context_processors.auth is enabled. My main issue with that is that it was incredibly hard to debug for me, when I passed my own 'perms' queryset to a template. So here's a (temporary) patch, to make it at least immediately fail.

{% for perm in perms %}
{% endfor %}

Attachments (2)

permwrapper.patch.bz2 (270 bytes ) - added by Uz 16 years ago.
8182_with_docs.diff (2.4 KB ) - added by Benjamin Schwarze 16 years ago.

Download all attachments as: .zip

Change History (8)

by Uz, 16 years ago

Attachment: permwrapper.patch.bz2 added

comment:1 by Uz, 16 years ago

permwrapper.patch only adds this to the PermWrapper class:

    def __iter__(self):
        raise NotImplementedError
}}

comment:2 by Collin Grady, 16 years ago

possible alternative?

    def __iter__(self):
        for p in self.user.get_all_permissions():
            yield p

by Benjamin Schwarze, 16 years ago

Attachment: 8182_with_docs.diff added

comment:3 by Benjamin Schwarze, 16 years ago

Added improved patch, which makes use of cgrady's idea.

The use of self.user.get_all_permissions() raised another problem -- this method doesn't exist for AnonymousUser. So I added the missing methods from User to the AnonymousUser class, providing adequate return values or raising NotImplementedError.

Updated docs for AnonymousUser as well.

comment:4 by Benjamin Schwarze, 16 years ago

Has patch: set

comment:5 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [8263]) No, really: PermWrapper is not iterable. Fixes #8182.

comment:6 by Jacob, 13 years ago

milestone: 1.0 beta

Milestone 1.0 beta deleted

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