﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17974	.distint('FIELDNAME') FAILS for MySQL	mschettler@…	nobody	"Hello -- I've long had a django 1.3 application using .distinct() successfully with my mysql backend.

Ive noticed a rather big (app breaking) issue in 1.4 release. Note, nothing else has changed except me updating to 1.4 today.

When I updated to 1.4 (via rev:17806 in django-trunk), I've been getting a 


{{{
  File ""/Applications/django-1.4/python/lib/python2.6/site-packages/django/db/backends/__init__.py"", line 572, in distinct_sql
    raise NotImplementedError('DISTINCT ON fields is not supported by this database backend')
NotImplementedError: DISTINCT ON fields is not supported by this database backend
}}}



This seems to have happened as a result of this changeset:
http://www.mail-archive.com/django-updates@googlegroups.com/msg81871.html


I think the issue is this: (from above changeset)


{{{
+        if fields:
+            raise NotImplementedError('DISTINCT ON fields is not supported by 
this database backend')
+        else:
+            return 'DISTINCT'
}}}



You'll notice from my attached shell session that when i call .distinct() with no fields, it works properly. As soon as I try .distinct('fieldname'), I get the above error.

I then made this change:


{{{
Index: django/db/backends/__init__.py
===================================================================
--- django/db/backends/__init__.py	(revision 17806)
+++ django/db/backends/__init__.py	(working copy)
@@ -568,7 +568,7 @@
         result set. If any fields are given, only the given fields are being
         checked for duplicates.
         """"""
-        if fields:
+        if not fields:
             raise NotImplementedError('DISTINCT ON fields is not supported by this database backend')
         else:
             return 'DISTINCT'


}}}


With this change in place, my code executes perfectly.

I have seen this bug in the 1.4 release, and as of writing current django-trunk. I've attached both my shell session and above patch to this ticket


Is this a bug? Or is something else going on at play locally with my setup? I've witnessed this both on my dev machine (OSX 10.7) and my deployment machine (UBUNTU 10.04)
"	Bug	closed	Database layer (models, ORM)	1.4	Normal	invalid	distinct on		Unreviewed	1	0	0	0	0	0
