.distint('FIELDNAME') FAILS for MySQL
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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:
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)
Change History (11)
comment:2 follow-up: 3 Changed 5 years ago by
|Status:||new → closed|