Opened 5 years ago

Closed 5 years ago

#12060 closed (fixed)

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

Reported by: ericholscher Owned by: lukeplant
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: UI/UX:

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 ericholscher 5 years ago.

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by ericholscher

comment:1 Changed 5 years ago by ericholscher

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Note that I meant r11623

comment:2 Changed 5 years ago by nathan

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 Changed 5 years ago by ericholscher

comment:4 Changed 5 years ago by lukeplant

  • Owner changed from nobody to lukeplant

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 5 years ago by lukeplant

  • Resolution set to fixed
  • Status changed from new to closed

(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