Edgewall Software

Opened 8 years ago

Last modified 8 years ago

#12298 closed defect

trac.db.tests.api test failures with sqlite — at Initial Version

Reported by: Christian Boos Owned by:
Priority: normal Milestone: 1.0.10
Component: database backend Version: 1.0dev
Severity: minor Keywords: sqlite
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I'm seeing some test failures on Windows (x64), Python 2.7.10 with sqlite3 module 2.6.0 (SQLite 3.6.21).

On 1.0-stable, the failure looks like this:

$ make test=trac/db/tests/api.py
[...]
python setup.py -q test -s trac.db.tests.api.suite
SKIP: fine-grained permission tests (ConfigObj not installed)
.........................E.............
======================================================================
ERROR: test_table_names (trac.db.tests.api.ConnectionTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "d:\trac\repos\1.0-stable\trac\db\tests\api.py", line 432, in setUp
    self.env.global_databasemanager.create_tables(self.schema)
  File "d:\trac\repos\1.0-stable\trac\db\api.py", line 266, in create_tables
    db(sql)
  File "d:\trac\repos\1.0-stable\trac\db\util.py", line 128, in execute
    cursor.execute(query, params if params is not None else [])
  File "d:\trac\repos\1.0-stable\trac\db\util.py", line 63, in execute
    r = self.cursor.execute(sql)
  File "d:\trac\repos\1.0-stable\trac\db\sqlite_backend.py", line 82, in execute
    result = PyFormatCursor.execute(self, *args)
  File "d:\trac\repos\1.0-stable\trac\db\sqlite_backend.py", line 60, in execute
    args or [])
  File "d:\trac\repos\1.0-stable\trac\db\sqlite_backend.py", line 52, in _rollback_on_error
    return function(self, *args, **kwargs)
OperationalError: table HOURS already exists

It's as if the DROP TABLE IF EXISTS statement wouldn't work reliably.

The following patch makes the tests pass again:

  • trac/db/sqlite_backend.py

     
    323323
    324324    def drop_table(self, table):
    325325        cursor = self.cursor()
    326         cursor.execute("DROP TABLE IF EXISTS " + self.quote(table))
     326        try:
     327            cursor.execute("DROP TABLE" + self.quote(table))
     328        except:
     329            pass
    327330
    328331    def get_column_names(self, table):
    329332        cursor = self.cnx.cursor()

However, it's not really satisfying…

Note that on Linux with Python 2.7.9 and sqlite3 2.6.0 as well, the error doesn't happen, but in this case the version of SQLite is 3.8.10.2.

So I built PySqlite 2.8.1 with latest SQLite (3.9.2), and there the above error doesn't happen either. PySqlite 2.8.1 no longer builds with SQLite 3.6.21, but PySqlite 2.7.0 does, and it triggers the error like sqlite3 did.

I'm now trying to pinpoint this problem to a specific version of SQLite.

Change History (0)

Note: See TracTickets for help on using tickets.