summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-06-30 18:48:01 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-06-30 18:48:01 -0400
commit9ae8de1f65c89f33f4ffae33023e481955f72244 (patch)
tree23ad61fc58654c78c409a6cc332db5080315ca0d
parent287e9d6a77ef20da98c28901fd118f4401aaab41 (diff)
downloadsqlalchemy-9ae8de1f65c89f33f4ffae33023e481955f72244.tar.gz
- 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".
-rw-r--r--CHANGES6
-rw-r--r--lib/sqlalchemy/schema.py1
-rw-r--r--test/sql/test_defaults.py12
3 files changed, 18 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index f220fb6d6..92881a341 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 9a49c785e..7323a5657 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 2bb961d4e..334a9d97c 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)