Django

Code

Ticket #8182 (closed: fixed)

Opened 4 months ago

Last modified 4 months ago

infinite loop iterating over context_processors.PermWrapper

Reported by: Uz Assigned to:
Milestone: 1.0 beta Component: Authentication
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

permwrapper.patch.bz2 (270 bytes) - added by Uz on 08/09/08 02:33:50.
8182_with_docs.diff (2.4 kB) - added by benjixx on 08/09/08 06:33:35.

Change History

08/09/08 02:33:50 changed by Uz

  • attachment permwrapper.patch.bz2 added.

08/09/08 03:47:09 changed by Uz

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

permwrapper.patch only adds this to the PermWrapper? class:

    def __iter__(self):
        raise NotImplementedError
}}

08/09/08 04:03:00 changed by cgrady

possible alternative?

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

08/09/08 06:33:35 changed by benjixx

  • attachment 8182_with_docs.diff added.

08/09/08 06:33:55 changed by benjixx

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.

08/09/08 06:34:24 changed by benjixx

  • has_patch set to 1.

08/09/08 10:38:45 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #8182 (infinite loop iterating over context_processors.PermWrapper)




Change Properties
Action