Opened 9 years ago

Closed 9 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


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 9 years ago.

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by Eric Holscher

Attachment: 12060.diff added

comment:1 Changed 9 years ago by Eric Holscher

Note that I meant r11623

comment:2 Changed 9 years ago by nathan

I have a very simple use case:


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 Changed 9 years ago by Eric Holscher

comment:4 Changed 9 years ago by Luke Plant

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 Changed 9 years ago by Luke Plant

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