]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix reflection of unknown types with arguments, NullType() accepts no arguments.
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Jan 2011 22:17:33 +0000 (17:17 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Jan 2011 22:17:33 +0000 (17:17 -0500)
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py

index ac0fde846809f27f1e4fac9646703047cdd72ea7..2fadda68c193fe49cb4211e4e12db1a56061ec78 100644 (file)
@@ -525,13 +525,13 @@ class SQLiteDialect(default.DefaultDialect):
                 args = ''
             try:
                 coltype = self.ischema_names[coltype]
+                if args is not None:
+                    args = re.findall(r'(\d+)', args)
+                    coltype = coltype(*[int(a) for a in args])
             except KeyError:
                 util.warn("Did not recognize type '%s' of column '%s'" %
                           (coltype, name))
-                coltype = sqltypes.NullType
-            if args is not None:
-                args = re.findall(r'(\d+)', args)
-                coltype = coltype(*[int(a) for a in args])
+                coltype = sqltypes.NullType()
 
             columns.append({
                 'name' : name,
index 11b0c004ebff80612965d628017fd60149c2efd7..2413c12e833fe2df638001593bba0d24da5827e6 100644 (file)
@@ -4,7 +4,7 @@ from test.lib.testing import eq_, assert_raises, \
     assert_raises_message
 import datetime
 from sqlalchemy import *
-from sqlalchemy import exc, sql, schema, pool
+from sqlalchemy import exc, sql, schema, pool, types as sqltypes
 from sqlalchemy.dialects.sqlite import base as sqlite, \
     pysqlite as pysqlite_dialect
 from test.lib import *
@@ -98,6 +98,7 @@ class TestTypes(TestBase, AssertsExecutionResults):
             assert not bindproc or isinstance(bindproc(u'some string'),
                     unicode)
 
+    @testing.provide_metadata
     def test_type_reflection(self):
 
         # (ask_for, roundtripped_as_if_different)
@@ -135,25 +136,33 @@ class TestTypes(TestBase, AssertsExecutionResults):
         columns = [Column('c%i' % (i + 1), t[0]) for (i, t) in
                    enumerate(specs)]
         db = testing.db
-        m = MetaData(db)
-        t_table = Table('types', m, *columns)
-        m.create_all()
+        t_table = Table('types', metadata, *columns)
+        metadata.create_all()
+        m2 = MetaData(db)
+        rt = Table('types', m2, autoload=True)
         try:
-            m2 = MetaData(db)
-            rt = Table('types', m2, autoload=True)
-            try:
-                db.execute('CREATE VIEW types_v AS SELECT * from types')
-                rv = Table('types_v', m2, autoload=True)
-                expected = [len(c) > 1 and c[1] or c[0] for c in specs]
-                for table in rt, rv:
-                    for i, reflected in enumerate(table.c):
-                        assert isinstance(reflected.type,
-                                type(expected[i])), '%d: %r' % (i,
-                                type(expected[i]))
-            finally:
-                db.execute('DROP VIEW types_v')
+            db.execute('CREATE VIEW types_v AS SELECT * from types')
+            rv = Table('types_v', m2, autoload=True)
+            expected = [len(c) > 1 and c[1] or c[0] for c in specs]
+            for table in rt, rv:
+                for i, reflected in enumerate(table.c):
+                    assert isinstance(reflected.type,
+                            type(expected[i])), '%d: %r' % (i,
+                            type(expected[i]))
         finally:
-            m.drop_all()
+            db.execute('DROP VIEW types_v')
+
+    @testing.emits_warning('Did not recognize')
+    @testing.provide_metadata
+    def test_unknown_reflection(self):
+        t = Table('t', metadata,
+            Column('x', sqltypes.BINARY(16)),
+            Column('y', sqltypes.BINARY())
+        )
+        t.create()
+        t2 = Table('t', MetaData(), autoload=True, autoload_with=testing.db)
+        assert isinstance(t2.c.x.type, sqltypes.NullType)
+        assert isinstance(t2.c.y.type, sqltypes.NullType)
 
 
 class TestDefaults(TestBase, AssertsExecutionResults):