From 6ec2246d04e3608a024b1425207c80c73fa78218 Mon Sep 17 00:00:00 2001 From: Tom Manderson Date: Tue, 30 Oct 2018 13:05:43 -0400 Subject: Move pk on single-inh subclass check below conflict resolution check The column conflict resolution technique discussed at :ref:`declarative_column_conflicts` is now functional for a :class:`.Column` that is also a primary key column. Previously, a check for primary key columns declared on a single-inheritance subclass would occur before the column copy were allowed to pass. Fixes: #4352 Change-Id: Id4c025da53c28e58db6b549fe398f25f8a90d355 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/483 (cherry picked from commit 3ed79a5c18c14d842280805d1dae8a9c99ec8f18) --- lib/sqlalchemy/ext/declarative/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py index 8ce44b936..f2b708f9f 100644 --- a/lib/sqlalchemy/ext/declarative/base.py +++ b/lib/sqlalchemy/ext/declarative/base.py @@ -534,11 +534,6 @@ class _MapperConfig(object): ) # add any columns declared here to the inherited table. for c in declared_columns: - if c.primary_key: - raise exc.ArgumentError( - "Can't place primary key columns on an inherited " - "class with no table." - ) if c.name in inherited_table.c: if inherited_table.c[c.name] is c: continue @@ -547,6 +542,11 @@ class _MapperConfig(object): "existing column '%s'" % (c, cls, inherited_table.c[c.name]) ) + if c.primary_key: + raise exc.ArgumentError( + "Can't place primary key columns on an inherited " + "class with no table." + ) inherited_table.append_column(c) if inherited_mapped_table is not None and \ inherited_mapped_table is not inherited_table: -- cgit v1.2.1