SimpleLazyObject missing __repr__ proxy
|Reported by:||spinus||Owned by:||fhahn|
|Cc:||flo@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
SimpleLazyObject (from django.utils.functionals) does not proxy _repr_ method.
User.__unicode__ -> print data for user, example: "firstname.lastname@example.org" User.__repr__ -> print debugging data, example: "<User pk:1, email:email@example.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
--- 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__")))
Change History (7)
comment:1 Changed 3 years ago by ptone
- Component changed from Uncategorized to Core (Other)
- Easy pickings set
- Needs documentation unset
- Needs tests set
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Accepted
- Version changed from 1.5-beta-1 to master
Changed 3 years ago by fhahn
comment:3 Changed 3 years ago by fhahn
- Cc flo@… added
- Needs tests unset
- Owner changed from nobody to fhahn
- Patch needs improvement unset
- Status changed from new to assigned