﻿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
7570	test failure with sqlite3 version < 3.3.6, typically on Windows: ORDER BY terms must not be non-integer constants	Karen Tracey <kmtracey@…>	nobody	"Running trunk r7787 on WinXP, Python2.5.2, the queries regression tests fail using sqlite3:

{{{
C:\u\kmt\django\trunk\tests>runtests.py --settings=testsettings queries
======================================================================
FAIL: Doctest: regressiontests.queries.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""c:\u\kmt\django\trunk\django\test\_doctest.py"", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for regressiontests.queries.models.__test__.API_TESTS
  File ""C:\u\kmt\django\trunk\tests\regressiontests\queries\models.py"", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File ""C:\u\kmt\django\trunk\tests\regressiontests\queries\models.py"", line ?, in regressiontests.queries.models.__test__.API_TESTS
Failed example:
    Item.objects.dates('created', 'day').extra(select={'a': 1})
Exception raised:
    Traceback (most recent call last):
      File ""c:\u\kmt\django\trunk\django\test\_doctest.py"", line 1267, in __run
        compileflags, 1) in test.globs
      File ""<doctest regressiontests.queries.models.__test__.API_TESTS[169]>"", line 1, in <module>
        Item.objects.dates('created', 'day').extra(select={'a': 1})
      File ""c:\u\kmt\django\trunk\django\db\models\query.py"", line 129, in __repr__
        return repr(list(self))
      File ""c:\u\kmt\django\trunk\django\db\models\query.py"", line 141, in __len__
        self._result_cache.extend(list(self._iter))
      File ""c:/u/kmt/django/trunk\django\db\models\sql\subqueries.py"", line 351, in results_iter
        for rows in self.execute_sql(MULTI):
      File ""c:\u\kmt\django\trunk\django\db\models\sql\query.py"", line 1607, in execute_sql
        cursor.execute(sql, params)
      File ""c:\u\kmt\django\trunk\django\db\backends\sqlite3\base.py"", line 136, in execute
        return Database.Cursor.execute(self, query, params)
    OperationalError: ORDER BY terms must not be non-integer constants


----------------------------------------------------------------------
Ran 1 test in 0.859s

FAILED (failures=1)

C:\u\kmt\django\trunk\tests>

}}}

I do not get this failure using sqlite3 on Linux for the tests, nor using MySQL on Windows.  So it's something specific to sqlite3 on Windows.  Recreating in the shell and showing the query that generates the error:

{{{

>>> Item.objects.dates('created', 'day').extra(select={'a': 1})
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""c:\u\kmt\django\trunk\django\db\models\query.py"", line 129, in __repr__
    return repr(list(self))
  File ""c:\u\kmt\django\trunk\django\db\models\query.py"", line 141, in __len__
    self._result_cache.extend(list(self._iter))
  File ""c:/u/kmt/django/trunk\django\db\models\sql\subqueries.py"", line 351, in results_iter
    for rows in self.execute_sql(MULTI):
  File ""c:\u\kmt\django\trunk\django\db\models\sql\query.py"", line 1607, in execute_sql
    cursor.execute(sql, params)
  File ""c:\u\kmt\django\trunk\django\db\backends\util.py"", line 18, in execute
    return self.cursor.execute(sql, params)
  File ""c:\u\kmt\django\trunk\django\db\backends\sqlite3\base.py"", line 136, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: ORDER BY terms must not be non-integer constants
>>> connection.queries[-1]
{'time': '0.000', 'sql': u'SELECT DISTINCT (1) AS ""a"", django_date_trunc(""day"", ""testfail_item"".""created"") FROM ""testfail_item"" ORDER BY 1 ASC'}
>>>

}}}

doesn't clarify anything for me.  I suspect this is a bug in the sqlite3/Windows combo rather than a bug in Django and I'm not even sure it's worth tracking down.  However it would be nice if the test suite could run without error for this combo, so if there was a way to rewrite this test to still test whatever it's supposed to be testing but not trigger this failure on Windows that might be good?  Only I don't quite understand what this test is trying to test, exactly, so I'm not sure how to even begin tweaking it to still do what it's intended to do without tripping over this sqlite3/Windows failure.

"		closed	Database layer (models, ORM)	dev		wontfix		richard.davies@…	Accepted	0	0	0	0	0	0
