Opened 7 years ago
Closed 7 years ago
#12060 closed (fixed)
Auth Context Processor returns user as a Lazy Object, which breaks things
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)
Change History (6)
Changed 7 years ago by
comment:1 Changed 7 years ago by
comment:2 Changed 7 years ago by
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 7 years ago by
This was also referenced on django-users as well:
comment:4 Changed 7 years ago by
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.
Note that I meant r11623