summaryrefslogtreecommitdiff
path: root/oslo_db/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-09-06 17:56:10 -0400
committerIhar Hrachyshka <ihrachys@redhat.com>2016-09-08 08:54:47 +0000
commit13223e459babddd74792699b20b52843a0ff9576 (patch)
tree090f218f9427fedc1dfff6bb6a2b0961bddfc502 /oslo_db/sqlalchemy
parentbf3b21f75b94a4d8b533dd10fdeb9a64da344cf9 (diff)
downloadoslo-db-13223e459babddd74792699b20b52843a0ff9576.tar.gz
Add additional caution looking for table, info4.13.3
A joined inheritance mapper is mapped to a join(); these have no .info attribute, so use that of the local table instead. The sorting order when querying against a joined subclass table can at least be derived from the base table, so use the base mapper's table. It may be a better idea to comprise the constraints amongst the base table *and* the joined table, though. Change-Id: I9466c9dbbbdc4af10ab0f15ee0f558199973c1ec (cherry picked from commit b19738a13a08f9ff5ac2357060250d121c680163)
Diffstat (limited to 'oslo_db/sqlalchemy')
-rw-r--r--oslo_db/sqlalchemy/utils.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py
index 016bae7..c5030a0 100644
--- a/oslo_db/sqlalchemy/utils.py
+++ b/oslo_db/sqlalchemy/utils.py
@@ -80,18 +80,22 @@ def _get_unique_keys(model):
except exc.NoInspectionAvailable:
return None
else:
- table = mapper.mapped_table
- if table is None:
+ local_table = mapper.local_table
+ base_table = mapper.base_mapper.local_table
+
+ if local_table is None:
return None
# extract result from cache if present
- info = table.info
- if 'oslodb_unique_keys' in info:
- return info['oslodb_unique_keys']
+ has_info = hasattr(local_table, 'info')
+ if has_info:
+ info = local_table.info
+ if 'oslodb_unique_keys' in info:
+ return info['oslodb_unique_keys']
res = []
try:
- constraints = table.constraints
+ constraints = base_table.constraints
except AttributeError:
constraints = []
for constraint in constraints:
@@ -100,14 +104,15 @@ def _get_unique_keys(model):
sqlalchemy.PrimaryKeyConstraint)):
res.append({c.name for c in constraint.columns})
try:
- indexes = table.indexes
+ indexes = base_table.indexes
except AttributeError:
indexes = []
for index in indexes:
if index.unique:
res.append({c.name for c in index.columns})
# cache result for next calls with the same model
- info['oslodb_unique_keys'] = res
+ if has_info:
+ info['oslodb_unique_keys'] = res
return res