db: Replace use of Query.get()
Resolve the following LegacyAPIWarning warning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() Change-Id: I30d0bccaddff6a1d91fcd5660f490f904e7c8965 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
9165c67c10
commit
5d2ab6c63b
|
@ -60,7 +60,7 @@ class Role(base.RoleDriverBase):
|
|||
return [role_ref.to_dict() for role_ref in role_refs]
|
||||
|
||||
def _get_role(self, session, role_id):
|
||||
ref = session.query(sql_model.RoleTable).get(role_id)
|
||||
ref = session.get(sql_model.RoleTable, role_id)
|
||||
if ref is None:
|
||||
raise exception.RoleNotFound(role_id=role_id)
|
||||
return ref
|
||||
|
|
|
@ -98,7 +98,7 @@ class Catalog(base.CatalogDriverBase):
|
|||
return [s.to_dict() for s in list(regions)]
|
||||
|
||||
def _get_region(self, session, region_id):
|
||||
ref = session.query(Region).get(region_id)
|
||||
ref = session.get(Region, region_id)
|
||||
if not ref:
|
||||
raise exception.RegionNotFound(region_id=region_id)
|
||||
return ref
|
||||
|
@ -186,7 +186,7 @@ class Catalog(base.CatalogDriverBase):
|
|||
return [s.to_dict() for s in list(services)]
|
||||
|
||||
def _get_service(self, session, service_id):
|
||||
ref = session.query(Service).get(service_id)
|
||||
ref = session.get(Service, service_id)
|
||||
if not ref:
|
||||
raise exception.ServiceNotFound(service_id=service_id)
|
||||
return ref
|
||||
|
@ -437,8 +437,9 @@ class Catalog(base.CatalogDriverBase):
|
|||
session.add(endpoint_filter_ref)
|
||||
|
||||
def _get_project_endpoint_ref(self, session, endpoint_id, project_id):
|
||||
endpoint_filter_ref = session.query(ProjectEndpoint).get(
|
||||
(endpoint_id, project_id))
|
||||
endpoint_filter_ref = session.get(
|
||||
ProjectEndpoint, (endpoint_id, project_id),
|
||||
)
|
||||
if endpoint_filter_ref is None:
|
||||
msg = _('Endpoint %(endpoint_id)s not found in project '
|
||||
'%(project_id)s') % {'endpoint_id': endpoint_id,
|
||||
|
@ -489,8 +490,7 @@ class Catalog(base.CatalogDriverBase):
|
|||
return endpoint_group_ref.to_dict()
|
||||
|
||||
def _get_endpoint_group(self, session, endpoint_group_id):
|
||||
endpoint_group_ref = session.query(EndpointGroup).get(
|
||||
endpoint_group_id)
|
||||
endpoint_group_ref = session.get(EndpointGroup, endpoint_group_id)
|
||||
if endpoint_group_ref is None:
|
||||
raise exception.EndpointGroupNotFound(
|
||||
endpoint_group_id=endpoint_group_id)
|
||||
|
@ -539,9 +539,9 @@ class Catalog(base.CatalogDriverBase):
|
|||
|
||||
def _get_endpoint_group_in_project(self, session,
|
||||
endpoint_group_id, project_id):
|
||||
endpoint_group_project_ref = session.query(
|
||||
ProjectEndpointGroupMembership).get((endpoint_group_id,
|
||||
project_id))
|
||||
endpoint_group_project_ref = session.get(
|
||||
ProjectEndpointGroupMembership, (endpoint_group_id, project_id),
|
||||
)
|
||||
if endpoint_group_project_ref is None:
|
||||
msg = _('Endpoint Group Project Association not found')
|
||||
raise exception.NotFound(msg)
|
||||
|
|
|
@ -78,7 +78,7 @@ class Credential(base.CredentialDriverBase):
|
|||
return [ref.to_dict() for ref in refs]
|
||||
|
||||
def _get_credential(self, session, credential_id):
|
||||
ref = session.query(CredentialModel).get(credential_id)
|
||||
ref = session.get(CredentialModel, credential_id)
|
||||
if ref is None:
|
||||
raise exception.CredentialNotFound(credential_id=credential_id)
|
||||
return ref
|
||||
|
|
|
@ -205,7 +205,7 @@ class Federation(base.FederationDriverBase):
|
|||
session.delete(idp_ref)
|
||||
|
||||
def _get_idp(self, session, idp_id):
|
||||
idp_ref = session.query(IdentityProviderModel).get(idp_id)
|
||||
idp_ref = session.get(IdentityProviderModel, idp_id)
|
||||
if not idp_ref:
|
||||
raise exception.IdentityProviderNotFound(idp_id=idp_id)
|
||||
return idp_ref
|
||||
|
@ -303,7 +303,7 @@ class Federation(base.FederationDriverBase):
|
|||
|
||||
# Mapping CRUD
|
||||
def _get_mapping(self, session, mapping_id):
|
||||
mapping_ref = session.query(MappingModel).get(mapping_id)
|
||||
mapping_ref = session.get(MappingModel, mapping_id)
|
||||
if not mapping_ref:
|
||||
raise exception.MappingNotFound(mapping_id=mapping_id)
|
||||
return mapping_ref
|
||||
|
@ -369,7 +369,7 @@ class Federation(base.FederationDriverBase):
|
|||
session.delete(sp_ref)
|
||||
|
||||
def _get_sp(self, session, sp_id):
|
||||
sp_ref = session.query(ServiceProviderModel).get(sp_id)
|
||||
sp_ref = session.get(ServiceProviderModel, sp_id)
|
||||
if not sp_ref:
|
||||
raise exception.ServiceProviderNotFound(sp_id=sp_id)
|
||||
return sp_ref
|
||||
|
|
|
@ -113,7 +113,7 @@ class Identity(base.IdentityDriverBase):
|
|||
|
||||
def _record_failed_auth(self, user_id):
|
||||
with sql.session_for_write() as session:
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
if not user_ref.local_user.failed_auth_count:
|
||||
user_ref.local_user.failed_auth_count = 0
|
||||
user_ref.local_user.failed_auth_count += 1
|
||||
|
@ -121,7 +121,7 @@ class Identity(base.IdentityDriverBase):
|
|||
|
||||
def _reset_failed_auth(self, user_id):
|
||||
with sql.session_for_write() as session:
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
user_ref.local_user.failed_auth_count = 0
|
||||
user_ref.local_user.failed_auth_at = None
|
||||
|
||||
|
@ -189,7 +189,7 @@ class Identity(base.IdentityDriverBase):
|
|||
user.default_project_id = None
|
||||
|
||||
def _get_user(self, session, user_id):
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
if not user_ref:
|
||||
raise exception.UserNotFound(user_id=user_id)
|
||||
return user_ref
|
||||
|
@ -258,7 +258,7 @@ class Identity(base.IdentityDriverBase):
|
|||
|
||||
def change_password(self, user_id, new_password):
|
||||
with sql.session_for_write() as session:
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
lock_pw_opt = user_ref.get_resource_option(
|
||||
options.LOCK_PASSWORD_OPT.option_id)
|
||||
if lock_pw_opt is not None and lock_pw_opt.option_value is True:
|
||||
|
@ -407,7 +407,7 @@ class Identity(base.IdentityDriverBase):
|
|||
return [ref.to_dict() for ref in refs]
|
||||
|
||||
def _get_group(self, session, group_id):
|
||||
ref = session.query(model.Group).get(group_id)
|
||||
ref = session.get(model.Group, group_id)
|
||||
if not ref:
|
||||
raise exception.GroupNotFound(group_id=group_id)
|
||||
return ref
|
||||
|
|
|
@ -64,7 +64,7 @@ class Mapping(base.MappingDriverBase):
|
|||
|
||||
def get_id_mapping(self, public_id):
|
||||
with sql.session_for_read() as session:
|
||||
mapping_ref = session.query(IDMapping).get(public_id)
|
||||
mapping_ref = session.get(IDMapping, public_id)
|
||||
if mapping_ref:
|
||||
return mapping_ref.to_dict()
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ class ShadowUsers(base.ShadowUsersDriverBase):
|
|||
def set_last_active_at(self, user_id):
|
||||
if CONF.security_compliance.disable_user_account_days_inactive:
|
||||
with sql.session_for_write() as session:
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
user_ref.last_active_at = datetime.datetime.utcnow().date()
|
||||
|
||||
@sql.handle_conflicts(conflict_type='federated_user')
|
||||
|
@ -210,7 +210,7 @@ class ShadowUsers(base.ShadowUsersDriverBase):
|
|||
return identity_base.filter_user(user_ref.to_dict())
|
||||
|
||||
def _get_user(self, session, user_id):
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
if not user_ref:
|
||||
raise exception.UserNotFound(user_id=user_id)
|
||||
return user_ref
|
||||
|
|
|
@ -86,7 +86,7 @@ class AccessToken(sql.ModelBase, sql.ModelDictMixin):
|
|||
|
||||
class OAuth1(base.Oauth1DriverBase):
|
||||
def _get_consumer(self, session, consumer_id):
|
||||
consumer_ref = session.query(Consumer).get(consumer_id)
|
||||
consumer_ref = session.get(Consumer, consumer_id)
|
||||
if consumer_ref is None:
|
||||
raise exception.NotFound(_('Consumer not found'))
|
||||
return consumer_ref
|
||||
|
@ -172,7 +172,7 @@ class OAuth1(base.Oauth1DriverBase):
|
|||
return token_ref.to_dict()
|
||||
|
||||
def _get_request_token(self, session, request_token_id):
|
||||
token_ref = session.query(RequestToken).get(request_token_id)
|
||||
token_ref = session.get(RequestToken, request_token_id)
|
||||
if token_ref is None:
|
||||
raise exception.NotFound(_('Request token not found'))
|
||||
return token_ref
|
||||
|
@ -231,7 +231,7 @@ class OAuth1(base.Oauth1DriverBase):
|
|||
return token_ref.to_dict()
|
||||
|
||||
def _get_access_token(self, session, access_token_id):
|
||||
token_ref = session.query(AccessToken).get(access_token_id)
|
||||
token_ref = session.get(AccessToken, access_token_id)
|
||||
if token_ref is None:
|
||||
raise exception.NotFound(_('Access token not found'))
|
||||
return token_ref
|
||||
|
|
|
@ -43,7 +43,7 @@ class Policy(rules.Policy):
|
|||
|
||||
def _get_policy(self, session, policy_id):
|
||||
"""Private method to get a policy model object (NOT a dictionary)."""
|
||||
ref = session.query(PolicyModel).get(policy_id)
|
||||
ref = session.get(PolicyModel, policy_id)
|
||||
if not ref:
|
||||
raise exception.PolicyNotFound(policy_id=policy_id)
|
||||
return ref
|
||||
|
|
|
@ -39,7 +39,7 @@ class Resource(base.ResourceDriverBase):
|
|||
return ref.id == base.NULL_DOMAIN_ID
|
||||
|
||||
def _get_project(self, session, project_id):
|
||||
project_ref = session.query(sql_model.Project).get(project_id)
|
||||
project_ref = session.get(sql_model.Project, project_id)
|
||||
if project_ref is None or self._is_hidden_ref(project_ref):
|
||||
raise exception.ProjectNotFound(project_id=project_id)
|
||||
return project_ref
|
||||
|
|
|
@ -141,7 +141,7 @@ class DomainConfig(base.DomainConfigDriverBase):
|
|||
|
||||
def read_registration(self, type):
|
||||
with sql.session_for_read() as session:
|
||||
ref = session.query(ConfigRegister).get(type)
|
||||
ref = session.get(ConfigRegister, type)
|
||||
if not ref:
|
||||
raise exception.ConfigRegistrationNotFound()
|
||||
return ref.domain_id
|
||||
|
|
|
@ -156,4 +156,4 @@ class ShadowUsersBackendTests(object):
|
|||
|
||||
def _get_user_ref(self, user_id):
|
||||
with sql.session_for_read() as session:
|
||||
return session.query(model.User).get(user_id)
|
||||
return session.get(model.User, user_id)
|
||||
|
|
|
@ -225,7 +225,7 @@ class UserResourceOptionTests(test_backend_sql.SqlTests):
|
|||
|
||||
def _get_user_ref(self, user_id):
|
||||
with sql.session_for_read() as session:
|
||||
return session.query(model.User).get(user_id)
|
||||
return session.get(model.User, user_id)
|
||||
|
||||
def _create_user(self, user_dict):
|
||||
user_dict['id'] = uuid.uuid4().hex
|
||||
|
@ -390,7 +390,7 @@ class DisableInactiveUserTests(test_backend_sql.SqlTests):
|
|||
|
||||
def _get_user_ref(self, user_id):
|
||||
with sql.session_for_read() as session:
|
||||
return session.query(model.User).get(user_id)
|
||||
return session.get(model.User, user_id)
|
||||
|
||||
def _create_user(self, user_dict, last_active_at):
|
||||
user_dict['id'] = uuid.uuid4().hex
|
||||
|
@ -402,7 +402,7 @@ class DisableInactiveUserTests(test_backend_sql.SqlTests):
|
|||
|
||||
def _update_user_last_active_at(self, user_id, last_active_at):
|
||||
with sql.session_for_write() as session:
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
user_ref.last_active_at = last_active_at
|
||||
return user_ref
|
||||
|
||||
|
@ -794,7 +794,7 @@ class PasswordExpiresValidationTests(test_backend_sql.SqlTests):
|
|||
driver = PROVIDERS.identity_api.driver
|
||||
driver.create_user(user_dict['id'], user_dict)
|
||||
with sql.session_for_write() as session:
|
||||
user_ref = session.query(model.User).get(user_dict['id'])
|
||||
user_ref = session.get(model.User, user_dict['id'])
|
||||
user_ref.password_ref.created_at = password_created_at
|
||||
user_ref.password_ref.expires_at = (
|
||||
user_ref._get_password_expires_at(password_created_at))
|
||||
|
@ -887,7 +887,7 @@ class MinimumPasswordAgeTests(test_backend_sql.SqlTests):
|
|||
# except the latest, need to have `created_at` slightly less than
|
||||
# the latest password.
|
||||
with sql.session_for_write() as session:
|
||||
user_ref = session.query(model.User).get(user_id)
|
||||
user_ref = session.get(model.User, user_id)
|
||||
latest_password = user_ref.password_ref
|
||||
slightly_less = datetime.timedelta(minutes=1)
|
||||
for password_ref in user_ref.local_user.passwords:
|
||||
|
|
|
@ -82,13 +82,6 @@ class WarningsFixture(fixtures.Fixture):
|
|||
# ...but filter everything out until we get around to fixing them
|
||||
# TODO(stephenfin): Fix all of these
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
module='keystone',
|
||||
message=r'The Query.get\(\) method is considered legacy .*',
|
||||
category=sqla_exc.SADeprecationWarning,
|
||||
)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
module='keystone',
|
||||
|
|
|
@ -1022,7 +1022,7 @@ class SqlTrust(SqlTests, trust_tests.TrustTests):
|
|||
with sql.session_for_write() as session:
|
||||
new_id = uuid.uuid4().hex
|
||||
self.create_sample_trust(new_id)
|
||||
trust_ref = session.query(trust_sql.TrustModel).get(new_id)
|
||||
trust_ref = session.get(trust_sql.TrustModel, new_id)
|
||||
self.assertIsNotNone(trust_ref._expires_at)
|
||||
self.assertEqual(trust_ref._expires_at, trust_ref.expires_at_int)
|
||||
self.assertEqual(trust_ref.expires_at, trust_ref.expires_at_int)
|
||||
|
|
|
@ -185,7 +185,7 @@ class Trust(base.TrustDriverBase):
|
|||
@sql.handle_conflicts(conflict_type='trust')
|
||||
def delete_trust(self, trust_id):
|
||||
with sql.session_for_write() as session:
|
||||
trust_ref = session.query(TrustModel).get(trust_id)
|
||||
trust_ref = session.get(TrustModel, trust_id)
|
||||
if not trust_ref:
|
||||
raise exception.TrustNotFound(trust_id=trust_id)
|
||||
trust_ref.deleted_at = timeutils.utcnow()
|
||||
|
|
Loading…
Reference in New Issue