db: Replace use of reverse cascades

Resolve the following RemovedIn20Warning warning:

  "ApplicationCredentialRoleModel" object is being merged into a Session
  along the backref cascade path for relationship
  "ApplicationCredentialModel.roles"; in SQLAlchemy 2.0, this reverse
  cascade will not take place.  Set cascade_backrefs to False in either
  the relationship() or backref() function for the 2.0 behavior; or to
  set globally for the whole Session, set the future=True flag

This also applies for "ApplicationCredentialAccessRuleModel" and
"AccessRuleModel.application_credential".

Change-Id: I277cb4d512ca6b4e4aca5aad60a97a78cdb961e3
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2023-02-28 12:57:36 +00:00
parent 5d2ab6c63b
commit 0bbaf63a5a
2 changed files with 6 additions and 13 deletions

View File

@ -44,11 +44,13 @@ class ApplicationCredentialModel(sql.ModelBase, sql.ModelDictMixin):
roles = sqlalchemy.orm.relationship(
'ApplicationCredentialRoleModel',
backref=sqlalchemy.orm.backref('application_credential'),
cascade='all, delete-orphan')
cascade='all, delete-orphan',
cascade_backrefs=False)
access_rules = sqlalchemy.orm.relationship(
'ApplicationCredentialAccessRuleModel',
backref=sqlalchemy.orm.backref('application_credential'),
cascade='all, delete-orphan')
cascade='all, delete-orphan',
cascade_backrefs=False)
class ApplicationCredentialRoleModel(sql.ModelBase, sql.ModelDictMixin):
@ -78,7 +80,8 @@ class AccessRuleModel(sql.ModelBase, sql.ModelDictMixin):
)
application_credential = sqlalchemy.orm.relationship(
'ApplicationCredentialAccessRuleModel',
backref=sqlalchemy.orm.backref('access_rule'))
backref=sqlalchemy.orm.backref('access_rule'),
cascade_backrefs=False)
class ApplicationCredentialAccessRuleModel(sql.ModelBase, sql.ModelDictMixin):

View File

@ -79,16 +79,6 @@ class WarningsFixture(fixtures.Fixture):
category=sqla_exc.SADeprecationWarning,
)
# ...but filter everything out until we get around to fixing them
# TODO(stephenfin): Fix all of these
warnings.filterwarnings(
'ignore',
module='keystone',
message=r'".*" object is being merged into a Session along .*',
category=sqla_exc.SADeprecationWarning,
)
self.addCleanup(self._reset_warning_filters)
def _reset_warning_filters(self):