Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1350 closed defect (fixed)

magic-removal: in_bulk id lookup fails if data hasn't been cached before

Reported by: andreas@… Owned by: Adrian Holovaty
Component: Core (Other) Version: magic-removal
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

The only way I can get in_bulk dictionary lookups to work is after forcing the complete data set to be read from db e.g. by calling repr before performing the lookup.

>>> polls = Poll.objects.in_bulk([1, 2, 3])
>>> # No data cached, lookup fails:
>>> polls[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/andreas/workspace/django-magic-removal/django/db/models/query.py",  line 103, in __getitem__
    return self._clone(_offset=k, _limit=1).get()
  File "/home/andreas/workspace/django-magic-removal/django/db/models/query.py",  line 159, in get
    obj_list = list(self.filter(*args, **kwargs))
  File "/home/andreas/workspace/django-magic-removal/django/db/models/query.py",  line 87, in __iter__
    return iter(self._get_data())
  File "/home/andreas/workspace/django-magic-removal/django/db/models/query.py",  line 391, in _get_data
    for i in self.iterator():
  File "/home/andreas/workspace/django-magic-removal/django/db/models/query.py",  line 385, in iterator
    self._where.append("%s.%s IN (%s)" % (backend.quote_name(self.model._meta.db _table), backend.quote_name(self.model._meta.pk.column), ",".join(['%s'] * len(s elf._id_list))))
AttributeError: 'InBulkQuerySet' object has no attribute '_id_list'
>>> # __repr__ caches the data:
>>> polls
{1: Poll #1, 2: Poll #2, 3: Poll #3}
>>> # now id lookup works:
>>> polls[1]
Poll #1

Change History (1)

comment:1 by Christopher Lenz <cmlenz@…>, 19 years ago

Resolution: fixed
Status: newclosed

This was fixed in [2354], but apparently Adrian forgot to close the ticket.

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