Closed apollodatasolutions closed 8 years ago
Hi, i remember encountering this bug but couldn't find anything in git logs, i'll try to make a unit test for this.
I managed to reproduce the issue, but the proposed solution only cures the symptoms, the real problem being that prefetch_related() is not implemented in EsQueryset. Adding the missing attributes allow to call prefetch_related, but the subsequent queries would be SQL queries ! So i decided to disallow the use of prefetch_related and override the incriminated methods so that the attributes should not be a problem anymore. Here is a PR, please tell me if it works for you.
We'll give it a shot, thanks!
We recently deployed a Django app to a live server and ran into an odd error we didn't experience in our dev and staging environment. The error, triggered by a template inclusion on a .mlt() query, is:
AttributeError at
'EsQueryset' object has no attribute '_prefetch_related_lookups'
Error originates from django/db/models/query.py in _fetch_all, line 966 in Django 1.8.3
We solved the issue by adding these three lines: self._prefetch_related_lookups = [] self._prefetch_done = False self._known_related_objects = {} to ... /django_elasticsearch/query.py in def init(self, model, fuzziness=None): of class EsQueryset(QuerySet):
Seems like this was added in Django 1.4 and wasn't reflected in the EsQuerySet class. Not sure why it wasn't triggered on our staging and only on live, so seems to be an edge case.