Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#21235 closed Bug (fixed)

1.6: Suggest installing standalone pysqlite2 on Windows when using Python 2.6

Reported by: Ramiro Morales Owned by: nobody
Component: Documentation Version: 1.6-beta-1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Running the stable/1.6.x tests on Windows with the latest official Python 2.6.6 binaries results on many errors:

Ran 5880 tests in 212.012s

FAILED (failures=6, errors=482, skipped=577, expected failures=11)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

Example of one of them:

ERROR: test_form_jump (django.contrib.formtools.tests.wizard.namedwizardtests.tests.NamedCookieWizardTests)
Traceback (most recent call last):
  File "C:\django\contrib\formtools\tests\wizard\namedwizardtests\", line 19, in setUp
    self.testuser, created = User.objects.get_or_create(username='testuser1')
  File "C:\django\db\models\", line 154, in get_or_create
    return self.get_queryset().get_or_create(**kwargs)
  File "C:\django\db\models\", line 388, in get_or_create
  File "C:\django\db\models\", line 379, in get_or_create
    with transaction.atomic(using=self.db):
  File "C:\django\db\", line 265, in __enter__
    sid = connection.savepoint()
  File "C:\django\db\backends\", line 227, in savepoint
  File "C:\django\db\backends\", line 197, in _savepoint
  File "C:\django\db\backends\", line 53, in execute
    return self.cursor.execute(sql, params)
  File "C:\django\db\", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\django\db\backends\", line 51, in execute
    return self.cursor.execute(sql)
  File "C:\django\db\backends\sqlite3\", line 444, in execute
    return Database.Cursor.execute(self, query)
OperationalError: near "SAVEPOINT": syntax error

This might be related to the versions of SQLite shared library and/or stdlib3 sqlite module shipped with these binaries:

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> print(sqlite3.sqlite_version)
>>> print(sqlite3.version)

According to our transactions document savepoint SQL syntax was added to SQLite3 in 3.6.8 (

Installing the latest pysqlite2 official binaries available ffor Python 2.6 (unfortunately only for 32 bits) at solves the problem (the remaining error and failure are unrelated):

Ran 5880 tests in 207.032s

FAILED (failures=1, errors=1, skipped=530, expected failures=11)

Perhaps we need to add a note about this to the relevant document (

Change History (4)

comment:1 Changed 5 years ago by Aymeric Augustin

Are you able to test the following patch?

diff --git a/django/db/backends/sqlite3/ b/django/db/backends/sqlite3/
index ac2376a..ef21423 100644
--- a/django/db/backends/sqlite3/
+++ b/django/db/backends/sqlite3/
@@ -393,12 +393,16 @@ class DatabaseWrapper(BaseDatabaseWrapper):
     def _savepoint_allowed(self):
+        # Two conditions are required here:
+        # - A sufficiently recent version of SQLite to support savepoints,
+        # - Being in a transaction, which can only happen inside 'atomic'.
         # When 'isolation_level' is not None, sqlite3 commits before each
         # savepoint; it's a bug. When it is None, savepoints don't make sense
-        # because autocommit is enabled. The only exception is inside atomic
-        # blocks. To work around that bug, on SQLite, atomic starts a
+        # because autocommit is enabled. The only exception is inside 'atomic'
+        # blocks. To work around that bug, on SQLite, 'atomic' starts a
         # transaction explicitly rather than simply disable autocommit.
-        return self.in_atomic_block
+        return self.features.uses_savepoints and self.in_atomic_block
     def _set_autocommit(self, autocommit):
         if autocommit:

comment:2 Changed 5 years ago by Ramiro Morales

Has patch: set
Triage Stage: UnreviewedAccepted

Tes, the proposed patch solves the reported problems.

comment:3 Changed 5 years ago by Aymeric Augustin <aymeric.augustin@…>

Resolution: fixed
Status: newclosed

In b42f0665a8cc25869c8dbc7bb71927b7ea61f81c:

[1.6.x] Fixed #21235 -- Disabled savepoints for old versions of SQLite.

Thanks Ramiro for the report.

Backport of 91547772 from master.

comment:4 Changed 5 years ago by Aymeric Augustin <aymeric.augustin@…>

In 91547772e04e456f45c7ef86e1f76d087821c89d:

Fixed #21235 -- Disabled savepoints for old versions of SQLite.

Thanks Ramiro for the report.

Note: See TracTickets for help on using tickets.
Back to Top