]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The SQLite dialect will now skip unsupported arguments when reflecting
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 16 Feb 2014 22:20:18 +0000 (17:20 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 16 Feb 2014 22:20:18 +0000 (17:20 -0500)
types; such as if it encounters a string like ``INTEGER(5)``, the
:class:`.INTEGER` type will be instantiated without the "5" being included,
based on detecting a ``TypeError`` on the first attempt.

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py

index 8e113f217f142924a1f22142c24bc15e17244a8a..3b2a65f7a2a3dd36a90c5b79ee3ffe91f036c07b 100644 (file)
     :version: 0.9.3
 
     .. change::
-        :tags: sqlite
+        :tags: sqlite, bug
+
+        The SQLite dialect will now skip unsupported arguments when reflecting
+        types; such as if it encounters a string like ``INTEGER(5)``, the
+        :class:`.INTEGER` type will be instantiated without the "5" being included,
+        based on detecting a ``TypeError`` on the first attempt.
+
+    .. change::
+        :tags: sqlite, bug
         :pullreq: github:65
 
         Support has been added to SQLite type reflection to fully support
index b285bc8ca5cd0beeb756c1c6d05fda9494098cb2..a1bd05d38b59f61e886768404a1d81bc671d6ae3 100644 (file)
@@ -867,7 +867,14 @@ class SQLiteDialect(default.DefaultDialect):
         coltype = self._resolve_type_affinity(coltype)
         if args is not None:
             args = re.findall(r'(\d+)', args)
-            coltype = coltype(*[int(a) for a in args])
+            try:
+                coltype = coltype(*[int(a) for a in args])
+            except TypeError:
+                util.warn(
+                        "Could not instantiate type %s with "
+                        "reflected arguments %s; using no arguments." %
+                        (coltype, args))
+                coltype = coltype()
 
         if default is not None:
             default = util.text_type(default)
index 319b708e7853924629a44d75f209afbc32b91c30..38bb783044bddf3414bb4d347fabea8ef8d04d78 100644 (file)
@@ -11,7 +11,9 @@ from sqlalchemy import Table, String, select, Text, CHAR, bindparam, Column,\
     Unicode, Date, MetaData, UnicodeText, Time, Integer, TIMESTAMP, \
     Boolean, func, NUMERIC, DateTime, extract, ForeignKey, text, Numeric,\
     DefaultClause, and_, DECIMAL, TypeDecorator, create_engine, Float, \
-    INTEGER, UniqueConstraint, DATETIME, DATE, TIME, BOOLEAN, BIGINT
+    INTEGER, UniqueConstraint, DATETIME, DATE, TIME, BOOLEAN, BIGINT, \
+    VARCHAR
+from sqlalchemy.types import UserDefinedType
 from sqlalchemy.util import u, ue
 from sqlalchemy import exc, sql, schema, pool, types as sqltypes, util
 from sqlalchemy.dialects.sqlite import base as sqlite, \
@@ -30,7 +32,7 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults):
         """Test that the boolean only treats 1 as True
 
         """
-        
+
         meta = MetaData(testing.db)
         t = Table('bool_table', meta, Column('id', Integer,
                   primary_key=True), Column('boo',
@@ -161,12 +163,20 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults):
             assert not bindproc or \
                 isinstance(bindproc(util.u('some string')), util.text_type)
 
+    @testing.emits_warning("Could not instantiate")
     @testing.provide_metadata
     def test_type_reflection(self):
         metadata = self.metadata
 
         # (ask_for, roundtripped_as_if_different)
 
+        class AnyType(UserDefinedType):
+            def __init__(self, spec):
+                self.spec = spec
+
+            def get_col_spec(self):
+              return self.spec
+
         specs = [
             (String(), String()),
             (String(1), String(1)),
@@ -198,11 +208,14 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults):
             (Time, Time()),
             (BOOLEAN, BOOLEAN()),
             (Boolean, Boolean()),
+            # types with unsupported arguments
+            (AnyType("INTEGER(5)"), INTEGER()),
+            (AnyType("DATETIME(6, 12)"), DATETIME()),
             ]
         columns = [Column('c%i' % (i + 1), t[0]) for (i, t) in
                    enumerate(specs)]
         db = testing.db
-        t_table = Table('types', metadata, *columns)
+        Table('types', metadata, *columns)
         metadata.create_all()
         m2 = MetaData(db)
         rt = Table('types', m2, autoload=True)
@@ -218,7 +231,6 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults):
         finally:
             db.execute('DROP VIEW types_v')
 
-    @testing.emits_warning('Did not recognize')
     @testing.provide_metadata
     def test_unknown_reflection(self):
         metadata = self.metadata