diff options
5 files changed, 17 insertions, 10 deletions
diff --git a/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py b/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py index fc06605e2..86eaeae3f 100644 --- a/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py +++ b/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py @@ -12,7 +12,6 @@ import migrate import sqlalchemy as sql -from sqlalchemy.engine import reflection from keystone.common.sql import upgrades @@ -20,7 +19,7 @@ from keystone.common.sql import upgrades def upgrade(migrate_engine): meta = sql.MetaData() meta.bind = migrate_engine - inspector = reflection.Inspector.from_engine(migrate_engine) + inspector = sql.inspect(migrate_engine) user = sql.Table('user', meta, autoload=True) local_user = sql.Table('local_user', meta, autoload=True) diff --git a/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py b/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py index ab5159f78..72a3f315f 100644 --- a/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py +++ b/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py @@ -22,7 +22,7 @@ def upgrade(migrate_engine): service_table = sql.Table('service', meta, autoload=True) region_table = sql.Table('region', meta, autoload=True) - inspector = sql.engine.reflection.Inspector.from_engine(migrate_engine) + inspector = sql.inspect(migrate_engine) for fk in inspector.get_foreign_keys('registered_limit'): if fk['referred_table'] == 'service': fkey = ForeignKeyConstraint([registered_limit_table.c.service_id], diff --git a/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py b/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py index b5b31e07b..d750bde53 100644 --- a/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py +++ b/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py @@ -26,7 +26,7 @@ def upgrade(migrate_engine): if migrate_engine.name != 'sqlite': project_table = sql.Table('project', meta, autoload=True) - inspector = sql.engine.reflection.Inspector.from_engine(migrate_engine) + inspector = sql.inspect(migrate_engine) for fk in inspector.get_foreign_keys('limit'): fkey = migrate.ForeignKeyConstraint( [limit_table.c.project_id], diff --git a/keystone/tests/unit/test_sql_upgrade.py b/keystone/tests/unit/test_sql_upgrade.py index 2e56b8a67..494797b58 100644 --- a/keystone/tests/unit/test_sql_upgrade.py +++ b/keystone/tests/unit/test_sql_upgrade.py @@ -56,8 +56,8 @@ from oslo_log import log from oslo_serialization import jsonutils from oslotest import base as test_base import pytz -from sqlalchemy.engine import reflection import sqlalchemy.exc +from sqlalchemy import inspect from testtools import matchers from keystone.cmd import cli @@ -312,13 +312,13 @@ class SqlMigrateBase(db_fixtures.OpportunisticDBTestMixin, def does_pk_exist(self, table, pk_column): """Check whether a column is primary key on a table.""" - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) pk_columns = inspector.get_pk_constraint(table)['constrained_columns'] return pk_column in pk_columns def does_fk_exist(self, table, fk_column): - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) for fk in inspector.get_foreign_keys(table): if fk_column in fk['constrained_columns']: return True @@ -333,7 +333,7 @@ class SqlMigrateBase(db_fixtures.OpportunisticDBTestMixin, return index_name in [idx.name for idx in table.indexes] def does_unique_constraint_exist(self, table_name, column_names): - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) constraints = inspector.get_unique_constraints(table_name) for c in constraints: if (len(c['column_names']) == 1 and @@ -668,7 +668,7 @@ class SqlLegacyRepoUpgradeTests(SqlMigrateBase): def test_add_trust_unique_constraint_upgrade(self): self.upgrade(86) - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) constraints = inspector.get_unique_constraints('trust') constraint_names = [constraint['name'] for constraint in constraints] self.assertIn('duplicate_trust_constraint', constraint_names) @@ -701,7 +701,7 @@ class SqlLegacyRepoUpgradeTests(SqlMigrateBase): session = self.sessionmaker() self.assertTableColumns('role', ['id', 'name', 'domain_id', 'extra']) # Check the domain_id has been added to the uniqueness constraint - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) constraints = inspector.get_unique_constraints('role') constraint_columns = [ constraint['column_names'] for constraint in constraints diff --git a/releasenotes/notes/use-correct-inspect-8142e317c1e39c2a.yaml b/releasenotes/notes/use-correct-inspect-8142e317c1e39c2a.yaml new file mode 100644 index 000000000..1fba8bdac --- /dev/null +++ b/releasenotes/notes/use-correct-inspect-8142e317c1e39c2a.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - > + Replaced the usage of SQLAlchemy Inspector.from_engine() with the + sqlalchemy.inspect() call, within several Alembic migration files as well + as a test suite. SQLAlchemy will be deprecating the former syntax, + so this change allows forwads compatibility with the next series of + SQLAlchemy. |