﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19543	SimpleLazyObject missing __repr__ proxy	spinus	fhahn	"SimpleLazyObject (from django.utils.functionals) does not proxy _repr_ method.
Use Case:

{{{
User.__unicode__ -> print data for user, example: ""user@email.com""
User.__repr__ -> print debugging data, example: ""<User pk:1, email:user@email.com, points:123>""
}}}

_unicode_ is used by most of application to render user content so I cant override it to using at logging. _repr_ is used in logging. 

Example user message: ""Hi %s""%request.user
Example logging message: ""%r just logged in""%request.user

When user is wrapped with SimpleLazyObject _repr_ method of User is not called. 
My idea is to make it available like

SimpleLazyObject._repr_ = lambda self: '<SimpleLazyObject: %r>'%self._wrapped


Patch:

{{{
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -303,6 +303,9 @@ class SimpleLazyObject(LazyObject):
     def __reduce__(self):
         return (self.__newobj__, (self.__class__,), self.__getstate__())
 
+    def __repr__(self):
+        return '<SimpleLazyObject: %r>' % self._wrapped
+
     # Need to pretend to be the wrapped class, for the sake of objects that care
     # about this (especially in equality tests)
     __class__ = property(new_method_proxy(operator.attrgetter(""__class__"")))
}}}

"	Bug	closed	Core (Other)	dev	Normal	fixed	SimpleLazyObject	flo@…	Ready for checkin	1	0	0	0	1	0
