Opened 15 years ago

Closed 15 years ago

#12060 closed (fixed)

Auth Context Processor returns user as a Lazy Object, which breaks things

Reported by: Eric Holscher Owned by: Luke Plant
Component: contrib.auth Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

With the addition in r11621, when a template checks the type or equality of request.user given from the auth context processor, you used to get:

ipdb> type(response.context['user'])
Out[0]: <class 'django.utils.functional.SimpleLazyObject'>

Previously, this returned an auth.User object.

<class 'django.contrib.auth.models.User'>

Attached is a test that fails with the current trunk. It passes with the current test structure and pre-r11621 auth context_processor.

Attachments (1)

12060.diff (795 bytes ) - added by Eric Holscher 15 years ago.

Download all attachments as: .zip

Change History (6)

by Eric Holscher, 15 years ago

Attachment: 12060.diff added

comment:1 by Eric Holscher, 15 years ago

Note that I meant r11623

comment:2 by nathan, 15 years ago

I have a very simple use case:

Filter:

@register.filter
def is_equal(obj, arg):
    "Returns a boolean of whether the value is equal to the argument"
    return obj == arg

Template (assuming a user is logged in):

{% if user|is_equal:book.user %} do something {% endif %}

This currently returns False if the user is in fact the same as the book user since it's being evaluated against 'SimpleLazyObject' instead of the actual user object.

comment:3 by Eric Holscher, 15 years ago

comment:4 by Luke Plant, 15 years ago

Owner: changed from nobody to Luke Plant

The attached test is not helpful, because it is effectively doing type checking. But testing for equality with a SimpleLazyObject-wrapped object ought to work, and that will be fixed.

comment:5 by Luke Plant, 15 years ago

Resolution: fixed
Status: newclosed

(In [11637]) Fixed #12060 - equality tests between User and SimpleLazyObject-wrapped User failed.

Also added more tests for SimpleLazyObject

Thanks to ericholscher for report.

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