From 4479d9ff91a19a2bad10e0f36cef6d9467d173ef Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 6 Jan 2025 16:37:04 -0600 Subject: [PATCH] fix: add `cascade_backrefs=False` for all ORM relationships prep for eventual SQLAlchemy 2.x --- src/wuttjamaican/db/model/batch.py | 11 +++++++---- src/wuttjamaican/db/model/upgrades.py | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wuttjamaican/db/model/batch.py b/src/wuttjamaican/db/model/batch.py index f6ba154..9b414b5 100644 --- a/src/wuttjamaican/db/model/batch.py +++ b/src/wuttjamaican/db/model/batch.py @@ -182,7 +182,6 @@ class BatchMixin: Reference to the :class:`~wuttjamaican.db.model.auth.User` who executed the batch. - """ @declared_attr @@ -231,7 +230,8 @@ class BatchMixin: return orm.relationship( User, primaryjoin=lambda: User.uuid == cls.created_by_uuid, - foreign_keys=lambda: [cls.created_by_uuid]) + foreign_keys=lambda: [cls.created_by_uuid], + cascade_backrefs=False) executed = sa.Column(sa.DateTime(timezone=True), nullable=True) @@ -242,7 +242,8 @@ class BatchMixin: return orm.relationship( User, primaryjoin=lambda: User.uuid == cls.executed_by_uuid, - foreign_keys=lambda: [cls.executed_by_uuid]) + foreign_keys=lambda: [cls.executed_by_uuid], + cascade_backrefs=False) def __repr__(self): cls = self.__class__.__name__ @@ -404,12 +405,14 @@ class BatchRowMixin: order_by=lambda: row_class.sequence, collection_class=ordering_list('sequence', count_from=1), cascade='all, delete-orphan', + cascade_backrefs=False, back_populates='batch') # now, here's the `BatchRow.batch` return orm.relationship( batch_class, - back_populates='rows') + back_populates='rows', + cascade_backrefs=False) sequence = sa.Column(sa.Integer(), nullable=False) diff --git a/src/wuttjamaican/db/model/upgrades.py b/src/wuttjamaican/db/model/upgrades.py index 6893ba6..750a9a6 100644 --- a/src/wuttjamaican/db/model/upgrades.py +++ b/src/wuttjamaican/db/model/upgrades.py @@ -52,6 +52,7 @@ class Upgrade(Base): created_by = orm.relationship( 'User', foreign_keys=[created_by_uuid], + cascade_backrefs=False, doc=""" :class:`~wuttjamaican.db.model.auth.User` who created the upgrade record. @@ -82,6 +83,7 @@ class Upgrade(Base): executed_by = orm.relationship( 'User', foreign_keys=[executed_by_uuid], + cascade_backrefs=False, doc=""" :class:`~wuttjamaican.db.model.auth.User` who executed the upgrade.