From 232eec47d13974e9c7bc7bafacba93ddbd59747d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 20 Oct 2016 17:36:59 -0400 Subject: Don't set pg autoincrement if type affinity is not Integer Postgresql table reflection will ensure that the :paramref:`.Column.autoincrement` flag is set to False when reflecting a primary key column that is not of an :class:`.Integer` datatype, even if the default is related to an integer-generating sequence. This can happen if a column is created as SERIAL and the datatype is changed. The autoincrement flag can only be True if the datatype is of integer affinity in the 1.1 series. This bug is related to a test failure in downstream sqlalchemy_migrate. Change-Id: I40260e47e1927a1ac940538408983c943bbdba28 Fixes: #3835 --- lib/sqlalchemy/dialects/postgresql/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 85f82ec60..9898e4ba4 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -2442,7 +2442,8 @@ class PGDialect(default.DefaultDialect): if default is not None: match = re.search(r"""(nextval\(')([^']+)('.*$)""", default) if match is not None: - autoincrement = True + if issubclass(coltype._type_affinity, sqltypes.Integer): + autoincrement = True # the default is related to a Sequence sch = schema if '.' not in match.group(2) and sch is not None: -- cgit v1.2.1