home / django_tickets / tickets

tickets: 8819

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8819 2008-09-03 00:54:18 2011-09-28 16:12:17 2022-03-06 03:43:15.128727 Unreviewed closed Core (Other)     dev fixed Regression: filter by extra(select = ..., order_by = ...) with distinct() fails ("Unknown column") 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. mtredinnick kevin@polimediagroup.com   0 0 0 0 0 0
Powered by Datasette · Queries took 0.663ms