Opened 13 years ago
Closed 13 years ago
#18538 closed Bug (wontfix)
type(SimpleLazyObject) returns SimpleLazyObject rather than type(_wrapped)
| Reported by: | Jeremy Dunck | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.4 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
In 1.4 we introduced request.user as a SimpleLazyObject. This has caused some bugs caused by abstraction leakage.
Today we ran across another - I'm expecting Router.allow_relation to be called with model instances (https://docs.djangoproject.com/en/1.4/topics/db/multi-db/#allow_relation) and using type() to get to the Model subclass.
type(obj1)._meta fails because type(obj1) returns SimpleLazyObject.
I've worked around by calling obj1.class (which is specifically proxied), but I'm noting the leakage here. I think there's nothing to be done (type is implemented in C (PyObject_Type) and reaches into the python object structure) but I am noting in here in case someone else has a bright idea for fixing it.
At least this ticket can serve as a workaround to others coming across this surprise. :)
Tough call on "component", could be ORM (since router in this case) or .auth (since that's what's Lazy'd).
Change History (3)
comment:1 by , 13 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 13 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 13 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
I also suspect there is nothing that can be done. Other approaches to making
request.userlazy:SimpleLazyObjectbecause of this problem.lazy- doesn't work because you don't know the type of user. It could be a third party class returned by a custom authentication backend.So I'm going to resolve as WONTFIX for now, but anyone with bright ideas for fixing this is welcome to re-open.