Commits

Mike Bayer committed bb3e635

- The path given as the location of a sqlite database is now
normalized via os.path.abspath(), so that directory changes
within the process don't affect the ultimate location
of a relative file path. [ticket:2036]

  • Participants
  • Parent commits a7f5813

Comments (0)

Files changed (5)

   - SQLite dialect now uses `NullPool` for file-based databases
     [ticket:1921]
 
+  - The path given as the location of a sqlite database is now
+    normalized via os.path.abspath(), so that directory changes
+    within the process don't affect the ultimate location
+    of a relative file path.  [ticket:2036]
+
 - mssql
   - the String/Unicode types, and their counterparts VARCHAR/
     NVARCHAR, emit "max" as the length when no length is 

lib/sqlalchemy/dialects/sqlite/pysqlite.py

 from sqlalchemy import types as sqltypes
 from sqlalchemy import util
 
+import os
 
 class _SQLite_pysqliteTimeStamp(DATETIME):
     def bind_processor(self, dialect):
                 " sqlite:///relative/path/to/file.db\n"
                 " sqlite:////absolute/path/to/file.db" % (url,))
         filename = url.database or ':memory:'
+        if filename != ':memory:':
+            filename = os.path.abspath(filename)
 
         opts = url.query.copy()
         util.coerce_kw_type(opts, 'timeout', float)

test/dialect/test_sqlite.py

 from sqlalchemy import exc, sql, schema, pool, types as sqltypes
 from sqlalchemy.dialects.sqlite import base as sqlite, \
     pysqlite as pysqlite_dialect
+from sqlalchemy.engine.url import make_url
 from test.lib import *
-
+import os
 
 class TestTypes(TestBase, AssertsExecutionResults):
 
                 pass
             raise
 
+    def test_file_path_is_absolute(self):
+        d = pysqlite_dialect.dialect()
+        eq_(
+            d.create_connect_args(make_url('sqlite:///foo.db')),
+            ([os.path.abspath('foo.db')], {})
+        )
+
     def test_pool_class(self):
         e = create_engine('sqlite+pysqlite://')
         assert e.pool.__class__ is pool.SingletonThreadPool
         eq_([1, 3], [r.id for r in results])
 
 
-class TestAutoIncrement(TestBase, AssertsCompiledSQL):
+class AutoIncrementTest(TestBase, AssertsCompiledSQL):
 
     def test_sqlite_autoincrement(self):
         table = Table('autoinctable', MetaData(), Column('id', Integer,

test/lib/requires.py

     # ODBC as well.
     return _chain_decorators_on(
         fn,
-        no_support('sqlite', 'no driver support'),
+        no_support('sqlite', 'Independent connections disabled when '
+                            ':memory: connections are used'),
         exclude('mssql', '<', (9, 0, 0),
                 'SQL Server 2005+ is required for independent connections'),
         )

test/orm/test_session.py

         assert session.connection().execute('select count(1) from users'
                 ).scalar() == 2
 
-    @testing.fails_on('sqlite', 'FIXME: unknown')
+    @testing.requires.independent_connections
     @testing.resolve_artifact_names
     def test_transactions_isolated(self):
         mapper(User, users)