From: Mike Bayer Date: Thu, 30 Jun 2011 22:48:01 +0000 (-0400) Subject: - Fixed bug where "autoincrement" detection on X-Git-Tag: rel_0_7_2~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ae8de1f65c89f33f4ffae33023e481955f72244;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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". --- diff --git a/CHANGES b/CHANGES index f220fb6d6b..92881a3416 100644 --- 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() diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 9a49c785e7..7323a5657a 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -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 \ diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index 2bb961d4e1..334a9d97c7 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -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)