Django

Code

Ticket #8819 (closed: fixed)

Opened 3 months ago

Last modified 3 months ago

Regression: filter by extra(select = ..., order_by = ...) with distinct() fails ("Unknown column")

Reported by: kevin@polimediagroup.com Assigned to: mtredinnick
Milestone: 1.0 Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Regression: adding an extra field to a QuerySet? using .extra(select = ...) with extra(order_by = ...) AND .distinct() throws an OperationalError?. This seems to be because the generated SQL lists the extra column twice: once correctly (as the derived field), and once just by itself at the end of the SELECT list.

Reduced test case below (using contrib.auth for simplified test case, though this is reproducible with any model).

import setup_django
from django.contrib.auth.models import User

a = User.objects.all().extra( select = { 'test_new_field': '1' }).distinct()
b = User.objects.all().extra( select = { 'test_new_field': '1' }, order_by = ['-test_new_field'] )
c = User.objects.all().extra( select = { 'test_new_field': '1' }, order_by = ['-test_new_field'] ).distinct()

print a[:1]
print b[:1]
print c[:1]

(In the code above, "setup_django" just sets the right settings file, etc.)

Expected: a, b, and c both evaluate without error. Actual: a and b are fine, c raises OperationalError?: (1054, "Unknown column 'test_new_field' in 'field list'")

I haven't tracked this down to a particular rev yet, but it's almost definitely within the past week or so.

Attachments

Change History

09/02/08 22:18:45 changed by mtredinnick

  • status changed from new to assigned.
  • needs_better_patch changed.
  • needs_tests changed.
  • milestone set to 1.0.
  • owner changed from nobody to mtredinnick.
  • needs_docs changed.

09/02/08 22:48:26 changed by mtredinnick

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [8898]) Fixed #8819 -- Don't include two copies of extra-select columns in the query. This was triggered by r8794, but was, in fact, fairly fragile before then. The current fix is the correct way we should be doing this.


Add/Change #8819 (Regression: filter by extra(select = ..., order_by = ...) with distinct() fails ("Unknown column"))




Change Properties
Action