django-nonrel / djangotoolbox

Django tools for building nonrel backends

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow Distinct Queries

gurelkaynak opened this issue · comments

I'm using django-nonrel 1.6-beta with djangotoolbox. Some of my admin pages needed to use DISTINCT but djangotoolbox prevented that in /db/basecompiler.py line 451:

diff --git a/djangotoolbox/db/basecompiler.py b/djangotoolbox/db/basecompiler.py
index 71d9ec8..47fa95b 100644
--- a/djangotoolbox/db/basecompiler.py
+++ b/djangotoolbox/db/basecompiler.py
@@ -451,7 +451,7 @@ class NonrelCompiler(SQLCompiler):
             raise EmptyResultSet()
         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):
+            self.query.extra or self.query.having):
             raise DatabaseError("This query is not supported by the database.")

     def get_count(self, check_exists=False):

Can somebody explain why using distinct raises this DatabaseError?

I'll also try to push this to a branch.

Thank you.

I realized that distinct queries are not supported by django_mongo_engine...

Actually they seem to be supported like this distinct('foo'). When called without arguments it doesn't work.