27 | | from {{{tests/regressiontests/queries/models.py}}} fails. |
| 29 | Error is: |
| 30 | |
| 31 | {{{ |
| 32 | ====================================================================== |
| 33 | FAIL: Doctest: regressiontests.queries.models.__test__.API_TESTS |
| 34 | ---------------------------------------------------------------------- |
| 35 | Traceback (most recent call last): |
| 36 | File "C:\ramiro\django-trunk\django\test\_doctest.py", line 2180, in runTest |
| 37 | raise self.failureException(self.format_failure(new.getvalue())) |
| 38 | AssertionError: Failed doctest test for regressiontests.queries.models.__test__.API_TESTS |
| 39 | File "C:\ramiro\django-trunk\tests\regressiontests\queries\models.py", line unknown line number, in API_TESTS |
| 40 | |
| 41 | ---------------------------------------------------------------------- |
| 42 | File "C:\ramiro\django-trunk\tests\regressiontests\queries\models.py", line ?, in regressiontests.queries.models.__test__.API_TESTS |
| 43 | Failed example: |
| 44 | Item.objects.dates('created', 'day').extra(select={'a': 1}) |
| 45 | Exception raised: |
| 46 | Traceback (most recent call last): |
| 47 | File "C:\ramiro\django-trunk\django\test\_doctest.py", line 1267, in __run |
| 48 | compileflags, 1) in test.globs |
| 49 | File "<doctest regressiontests.queries.models.__test__.API_TESTS[169]>", line 1, in <module> |
| 50 | Item.objects.dates('created', 'day').extra(select={'a': 1}) |
| 51 | File "c:\ramiro\django-trunk\django\db\models\query.py", line 129, in __repr__ |
| 52 | return repr(list(self)) |
| 53 | File "c:\ramiro\django-trunk\django\db\models\query.py", line 141, in __len__ |
| 54 | self._result_cache.extend(list(self._iter)) |
| 55 | File "c:\ramiro\django-trunk\django\db\models\sql\subqueries.py", line 351, in results_iter |
| 56 | for rows in self.execute_sql(MULTI): |
| 57 | File "c:\ramiro\django-trunk\django\db\models\sql\query.py", line 1607, in execute_sql |
| 58 | cursor.execute(sql, params) |
| 59 | File "c:\ramiro\django-trunk\django\db\backends\sqlite3\base.py", line 136, in execute |
| 60 | return Database.Cursor.execute(self, query, params) |
| 61 | OperationalError: ORDER BY terms must not be non-integer constants |
| 62 | |
| 63 | |
| 64 | ---------------------------------------------------------------------- |
| 65 | Ran 253 tests in 433.032s |
| 66 | |
| 67 | FAILED (failures=1) |
| 68 | }}} |
99 | | TBD |
| 138 | {{{ |
| 139 | #!python |
| 140 | >>> from pysqlite2 import dbapi2 |
| 141 | >>> print dbapi2.version_info |
| 142 | (2, 4, 1) |
| 143 | >>> print dbapi2.sqlite_version_info |
| 144 | (3, 5, 2) |
| 145 | >>> |
| 146 | }}} |
| 147 | |
| 148 | The error doesn't show itself when running the tests if one manages to force Django to use this newer version of pysqlite (see below). This seems to indicate that something was fixed on sqlite between versions 3.3.4 and 3.5.2 (see http://sqlite.org/changes.html). |
| 149 | |
| 150 | ==== How does this affect Django ==== |
| 151 | |
| 152 | The problem doesn't lie with Django, but leads to ask if the order being used to try loading the sqlite-related DB-API2 modules by the sqlite3 backed ({{{django/db/backends/sqlite3/base.py}}}) shouldn't be inverted: Try loading pysqlite2 first and if it fails then try loading sqlite3: |
| 153 | |
| 154 | {{{ |
| 155 | #!diff |
| 156 | --- base.py 2008-04-27 00:58:35.000000000 -0300 |
| 157 | +++ base.py-proposed 2008-06-29 20:48:29.000000000 -0300 |
| 158 | @@ -3,15 +3,16 @@ |
| 159 | |
| 160 | Python 2.3 and 2.4 require pysqlite2 (http://pysqlite.org/). |
| 161 | |
| 162 | -Python 2.5 and later use the sqlite3 module in the standard library. |
| 163 | +Python 2.5 and later use pysqlite2 or the sqlite3 module in the standard |
| 164 | +library. |
| 165 | """ |
| 166 | |
| 167 | from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util |
| 168 | try: |
| 169 | try: |
| 170 | - from sqlite3 import dbapi2 as Database |
| 171 | - except ImportError: |
| 172 | from pysqlite2 import dbapi2 as Database |
| 173 | + except ImportError: |
| 174 | + from sqlite3 import dbapi2 as Database |
| 175 | except ImportError, e: |
| 176 | import sys |
| 177 | from django.core.exceptions import ImproperlyConfigured |
| 178 | }}} |
| 179 | |
| 180 | Reasoning behind this is that this would allow the user to take advantage of newer pysqlite2/sqlite3 versions he/she may have installed even if using Python 2.5. This might be true regardless of the platform. |