]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed regression from 0.6 where SMALLINT and
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 18 Feb 2011 01:43:17 +0000 (20:43 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 18 Feb 2011 01:43:17 +0000 (20:43 -0500)
BIGINT types would both generate SERIAL
on an integer PK column, instead of
SMALLINT and BIGSERIAL [ticket:2065]

CHANGES
lib/sqlalchemy/types.py
test/dialect/test_postgresql.py

diff --git a/CHANGES b/CHANGES
index 3d834b330d17ab3f1a5257fe06712b6bfa3c184e..f60c5fe7d12bf29d9b8441da3148e02b4bd4c30f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -34,6 +34,12 @@ CHANGES
     given column exactly, not just it's parent
     table.  [ticket:2064]
 
+- postgresql
+  - Fixed regression from 0.6 where SMALLINT and
+    BIGINT types would both generate SERIAL
+    on an integer PK column, instead of 
+    SMALLINT and BIGSERIAL [ticket:2065]
+
 - ext
   - Association proxy now has correct behavior for
     any(), has(), and contains() when proxying
index a46cb15309fbe51b47288edc2316c527791cc8cc..71b55f33f9923d15d7ae15b736ce9f5d8141a425 100644 (file)
@@ -1007,6 +1007,10 @@ class SmallInteger(Integer):
 
     __visit_name__ = 'small_integer'
 
+    @property
+    def _type_affinity(self):
+        return SmallInteger
+
 class BigInteger(Integer):
     """A type for bigger ``int`` integers.
 
@@ -1017,6 +1021,10 @@ class BigInteger(Integer):
 
     __visit_name__ = 'big_integer'
 
+    @property
+    def _type_affinity(self):
+        return BigInteger
+
 class Numeric(_DateAffinity, TypeEngine):
     """A type for fixed precision numbers.
 
index 1c7d0b16a43e8b6e66f41c2d240b055fd2115ea8..149421404a7c0f2150cb3af09397dd26e0b1bdd0 100644 (file)
@@ -1495,6 +1495,23 @@ class MiscTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
                     : Numeric})
         assert_raises(exc.InvalidRequestError, testing.db.execute, stmt)
 
+    def test_serial_integer(self):
+        for type_, expected in [
+            (Integer, 'SERIAL'),
+            (BigInteger, 'BIGSERIAL'),
+            (SmallInteger, 'SMALLINT'),
+            (postgresql.INTEGER, 'SERIAL'),
+            (postgresql.BIGINT, 'BIGSERIAL'),
+        ]:
+            m = MetaData()
+
+            t = Table('t', m, Column('c', type_, primary_key=True))
+            ddl_compiler = testing.db.dialect.ddl_compiler(testing.db.dialect, schema.CreateTable(t))
+            eq_(
+                ddl_compiler.get_column_specification(t.c.c),
+                "c %s NOT NULL" % expected
+            )
+
 class TimezoneTest(TestBase):
 
     """Test timezone-aware datetimes.