]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where "autoincrement" detection on
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 30 Jun 2011 22:48:01 +0000 (18:48 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 30 Jun 2011 22:48:01 +0000 (18:48 -0400)
Table would fail if the type had no "affinity"
value, in particular this would occur when using
the UUID example on the site that uses TypeEngine
as the "impl".

CHANGES
lib/sqlalchemy/schema.py
test/sql/test_defaults.py

diff --git a/CHANGES b/CHANGES
index f220fb6d6bbb731e0379a66a691b9c754786dfbe..92881a3416464e24a25a5ce870bf7a19fbc419fd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -49,6 +49,12 @@ CHANGES
     event in 0.6 would get "tables=somecollection",
     this behavior is preserved.  [ticket:2206]
 
+  - Fixed bug where "autoincrement" detection on 
+    Table would fail if the type had no "affinity"
+    value, in particular this would occur when using 
+    the UUID example on the site that uses TypeEngine
+    as the "impl".
+
 - engine
   - Use urllib.parse_qsl() in Python 2.6 and above,
     no deprecation warning about cgi.parse_qsl()
index 9a49c785e7ceba0a31c8862e39004268e88d7f2b..7323a5657ae00fe0da3c72b03da9a2101b787d14 100644 (file)
@@ -390,6 +390,7 @@ class Table(SchemaItem, expression.TableClause):
     def _autoincrement_column(self):
         for col in self.primary_key:
             if col.autoincrement and \
+                col.type._type_affinity is not None and \
                 issubclass(col.type._type_affinity, sqltypes.Integer) and \
                 not col.foreign_keys and \
                 isinstance(col.default, (type(None), Sequence)) and \
index 2bb961d4e15918e598f8a413f5241d9af95a17be..334a9d97c73ee6cd65c2440041c07f603bfa77a2 100644 (file)
@@ -6,7 +6,7 @@ import sqlalchemy as sa
 from test.lib import testing, engines
 from sqlalchemy import MetaData, Integer, String, ForeignKey, Boolean, exc,\
                 Sequence, func, literal, Unicode
-from sqlalchemy.types import TypeDecorator
+from sqlalchemy.types import TypeDecorator, TypeEngine
 from test.lib.schema import Table, Column
 from test.lib.testing import eq_
 from sqlalchemy.dialects import sqlite
@@ -542,6 +542,16 @@ class AutoIncrementTest(fixtures.TablesTest):
         id_ = r.inserted_primary_key[0]
         nodes.insert().execute(data='bar', parent_id=id_)
 
+    def test_autoinc_detection_no_affinity(self):
+        class MyType(TypeDecorator):
+            impl = TypeEngine
+
+        assert MyType()._type_affinity is None
+        t = Table('x', MetaData(),
+            Column('id', MyType(), primary_key=True)
+        )
+        assert t._autoincrement_column is None
+
     @testing.fails_on('sqlite', 'FIXME: unknown')
     def test_non_autoincrement(self):
         # sqlite INT primary keys can be non-unique! (only for ints)