id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 1350 magic-removal: in_bulk id lookup fails if data hasn't been cached before andreas@… Adrian Holovaty "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 """", 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 }}} " defect closed Core (Other) magic-removal normal fixed Unreviewed 0 0 0 0 0 0