Opened 12 years ago

Last modified 12 years ago

#19616 closed Bug

QuerySet.__contains__ tries to check the length of a None — at Initial Version

Reported by: kalugny@… 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: yes UI/UX: no

Description

This is the code from QuerySet (version 1.42).
As you can see by the lines I've bolded, although _result_cache might be None, it is still being checked for len()

def contains(self, val):

# The 'in' operator works without this method, due to iter. This
# implementation exists only to shortcut the creation of Model
# instances, by bailing out early if we find a matching element.
pos = 0
if self._result_cache is not None:

if val in self._result_cache:

return True

elif self._iter is None:

# iterator is exhausted, so we have our answer
return False

# remember not to check these again:
pos = len(self._result_cache)

else:

# We need to start filling the result cache out. The following
# ensures that self._iter is not None and self._result_cache is not
# None
it = iter(self)

# Carry on, one result at a time.
while True:

if len(self._result_cache) <= pos:

self._fill_cache(num=1)

Change History (0)

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