summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-09-04 17:44:48 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-09-04 17:44:48 +0000
commit94c32b19a08182aa5403a893ffd037994199ca44 (patch)
tree15e08f101e7292cbf4a636bccbeea97f28f74bcd /lib/sqlalchemy/sql/util.py
parentcd8a3390e6992a1a969af47ee6268456d7890aa8 (diff)
downloadsqlalchemy-94c32b19a08182aa5403a893ffd037994199ca44.tar.gz
- Fixed bug whereby mapper couldn't initialize if a composite
primary key referenced another table that was not defined yet [ticket:1161]
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r--lib/sqlalchemy/sql/util.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index e1636ccf9..d9c3ed899 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -190,7 +190,7 @@ def splice_joins(left, right, stop_on=None):
return ret
-def reduce_columns(columns, *clauses):
+def reduce_columns(columns, *clauses, **kw):
"""given a list of columns, return a 'reduced' set based on natural equivalents.
the set is reduced to the smallest list of columns which have no natural
@@ -200,12 +200,17 @@ def reduce_columns(columns, *clauses):
\*clauses is an optional list of join clauses which will be traversed
to further identify columns that are "equivalent".
+ \**kw may specify 'ignore_nonexistent_tables' to ignore foreign keys
+ whose tables are not yet configured.
+
This function is primarily used to determine the most minimal "primary key"
from a selectable, by reducing the set of primary key columns present
in the the selectable to just those that are not repeated.
"""
+ ignore_nonexistent_tables = kw.pop('ignore_nonexistent_tables', False)
+
columns = util.OrderedSet(columns)
omit = set()
@@ -214,7 +219,14 @@ def reduce_columns(columns, *clauses):
for c in columns:
if c is col:
continue
- if fk.column.shares_lineage(c):
+ try:
+ fk_col = fk.column
+ except exc.NoReferencedTableError:
+ if ignore_nonexistent_tables:
+ continue
+ else:
+ raise
+ if fk_col.shares_lineage(c):
omit.add(col)
break