wlanslovenija / django-tastypie-mongoengine

MongoEngine support for django-tastypie.
Other
73 stars 59 forks source link

Not compatible with QuerySetNoCache() #76

Open mgoffin opened 10 years ago

mgoffin commented 10 years ago

If you are inheriting from MongoEngine's QuerySetNoCache() instead of QuerySet() for a custom QuerySet, the you will get the following error:

File \"/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tastypie/resources.py\", line 1930, in build_filters

    query_terms = self._meta.queryset.query.query_terms

AttributeError: 'CustomQuerySet' object has no attribute 'query'

If you lift the code from lines 32-41 of resources.py and add it to your custom QuerySet class, things will work. Seems like that code is very specific to using the cached QuerySet and not supporting the non-cached version?

mitar commented 9 years ago

This is code from Tastypie. We extend the code which assumes that it uses Django ORM, and then we override things for MongoEngine.

It would be helpful if you provide whole stack. Because then we could see where from this code is called and if it goes somewhere through our code. Maybe in some other case we already have a workaround, which checks for example for class instance and is not patching here the queryset.

The best would be if you could make a pull request with the test which is failing for you.