Closed tjohns closed 11 years ago
Specifically, here's the method in django-nonrel that's generating the error:
djangotoolbox/db/basecompiler.py:
def check_query(self):
"""
Checks if the current query is supported by the database.
In general, we expect queries requiring JOINs (many-to-many
relations, abstract model bases, or model spanning filtering),
using DISTINCT (through `QuerySet.distinct()`, which is not
required in most situations) or using the SQL-specific
`QuerySet.extra()` to not work with nonrel back-ends.
"""
if (len([a for a in self.query.alias_map if
self.query.alias_refcount[a]]) > 1 or
self.query.distinct or self.query.extra or self.query.having):
raise DatabaseError("This query is not supported by the database.")
It sounds like the models have foreign-key relationships, which Django Rest Framework is following. Django-nonrel does not support them (by design) and throws an exception when they are used.
As @kevin-brown notes this'll be to do with the types of model relationships/lookups that GAE supports.
You're not going to be able to simply port the generic views across to GAE without taking into account the differences in GAE datastore vs relational databases. I'd strongly suggest working with APIView and regular Serializers if you want to use app engine, so that you're dealing with any model behaviour explicitly.
I'm going to close this ticket, as we don't claim support for GAE - I'd love for someone to document any considerations when running with non-rel, or packaging up any differences that might be required to make the generic views and/or model serializers work more seamlessly with it, but if that does happen it needs to be someone taking that on independently (with us linking to them from the main docs), rather than as part of the core REST framework project.
Thanks for clarifying.
As an aside, for anyone else who comes across this ticket: I did get things working with my own custom models. Specifically, the Polls/Choices models listed in the django-rest-framework tutorial work without any changes.
It seems it was just the Users/Groups models provided by the framework that were giving me trouble.
Given that most apps using django-nonrel are going to avoid using ForeignKey in their own models (because of GAE's restrictions), this doesn't seem to be a huge issue.
ForeignKeys are not the problem. They are working just fine. As stated in the docs, many to many relationships and joins are not supported by django nonrel. I could work around this issue by omitting the groups relation with a custom serializer:
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username', 'email', 'password', 'first_name', 'last_name')
Thanks thochi! Work greak
changing the fields worked like charm. Thanks thochi
Hey folks,
I am facing the same or similar issue where django 1.6 non-rel do not support a query below. It looks like I need a custom serializer but current restframework requires django 1.8 http://www.django-rest-framework.org/#requirements. I am wondering where can I get rest_framework for 1.6 non-rel? Perhaps there is some other workaround?
super(FindResultsDataView, self).get_queryset().filter(feature__name = 'name') *** DatabaseError: This query is not supported by the database.
I'm trying to get a basic django-rest-framework app up and running using AppEngine, via django-nonrel.
When I try to get the tutorial running, navigating to /users or /groups gives me the following error: "This query is not supported by the database."
Full stack trace below: