Opened 4 years ago

Closed 4 years ago

#23782 closed Uncategorized (worksforme)

Lazy objects don't support __contains__

Reported by: German M. Bravo Owned by: nobody
Component: Uncategorized Version: 1.7
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

While trying to use SimpleLazyObject to check if something is contained in an object, the following throws an exception (AttributeError: 'int' object has no attribute 'lower') when the not in fallback to the sequence iteration protocol: 'Content-Language' not in SimpleLazyObject(lambda: HttpResponseRedirect('/'))

Attachments (1)

#23782-lazy_with_contains.diff (438 bytes) - added by German M. Bravo 4 years ago.

Download all attachments as: .zip

Change History (3)

Changed 4 years ago by German M. Bravo

comment:1 Changed 4 years ago by Jakub Paczkowski

I see this operator in SimpleLazyObject here: https://github.com/django/django/blob/1.7/django/utils/functional.py#L330
Also added a test to check if it behaves as expected: https://github.com/django/django/pull/3514

comment:2 Changed 4 years ago by Jakub Paczkowski

Resolution: worksforme
Status: newclosed

What is more, these tests already exists in https://github.com/django/django/blob/master/tests/utils_tests/test_lazyobject.py
The contains method was added to the code in this commit: https://github.com/django/django/commit/7a698c05b56d7d5e267241dc71c16c403efd2965

So I'm closing this issue as worksforme

Note: See TracTickets for help on using tickets.
Back to Top