You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding annotate to a QuerySet that is to be cached, it throws a Key Error exception (see below - CommentAttachment has a foreign key point to a Comment model). It works find if counting within the same model, but not with a related model (e.g. through the foreign key)
Note: The error only occurs the first time the query is run.
Comment.objects.cache().filter(id = 1).annotate(Count('commentattachment'))
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 68, in repr
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 83, in len
self._result_cache.extend(list(self._iter))
File "/usr/lib/python2.6/dist-packages/cachebot/queryset.py", line 434, in iterator
for obj in CacheBot(self):
File "/usr/lib/python2.6/dist-packages/cachebot/queryset.py", line 65, in iter
self.cache_results(results)
File "/usr/lib/python2.6/dist-packages/cachebot/queryset.py", line 107, in cache_results
invalidation_dict.update(dict([(key, self.result_key) for key in self.get_invalidation_keys(results)]))
File "/usr/lib/python2.6/dist-packages/cachebot/queryset.py", line 159, in get_invalidation_keys
related_fields = self.queryset._related_fields
File "/usr/lib/python2.6/dist-packages/cachebot/queryset.py", line 204, in _related_fields
for attname, model_class in self._get_related_models(self.model):
File "/usr/lib/python2.6/dist-packages/cachebot/queryset.py", line 227, in _get_related_models
for join_attname, model_klass in self._get_related_models(model_class):
File "/usr/lib/python2.6/dist-packages/cachebot/queryset.py", line 217, in _get_related_models
related_models.add((rev_reversemapping[attname], related.model))
KeyError: 'update_set'
Comment.objects.cache().filter(id = 1).annotate(Count('commentattachment'))
[]
The text was updated successfully, but these errors were encountered:
I have a similar issue. In my case, somehow the auth_user table sneaks into the list of tables for the query and then _get_related_models goes through the reverse relations for the auth_user model and eventually craps out. I don't really get it why auth_user gets returned in the self.query.tables call. Something is wrong. If you have a fix for this, please let me know.
When adding annotate to a QuerySet that is to be cached, it throws a Key Error exception (see below - CommentAttachment has a foreign key point to a Comment model). It works find if counting within the same model, but not with a related model (e.g. through the foreign key)
Note: The error only occurs the first time the query is run.
The text was updated successfully, but these errors were encountered: