Opened 5 months ago

Last modified 3 months ago

#28358 assigned Bug

LazyObject defines attribute that don't exist on wrapped object

Reported by: Andrey Fedoseev Owned by: Sergey Fedoseev
Component: Utilities Version: 1.11
Severity: Normal Keywords:
Cc: Sergey Fedoseev Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

LazyObject defines magic methods (__getitem__, __iter__) which may be missing from the wrapped object. This leads to the following errors:

some_variable = request.user

if hasattr(some_variable, "__getitem__"):
    foo = some_variable["foo"]  # raises TypeError: 'User' object has no attribute '__getitem__'

if hasattr(some_variable, "__iter__"):
    for item in some_variable:  # raises TypeError: 'User' object is not iterable

Change History (5)

comment:1 Changed 5 months ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:2 Changed 5 months ago by Sergey Fedoseev

Cc: Sergey Fedoseev added

comment:3 Changed 5 months ago by Sergey Fedoseev

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:4 Changed 4 months ago by Sergey Fedoseev

Has patch: set

comment:5 Changed 3 months ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top