3
0
Fork 0

fix: add cascade_backrefs=False for all ORM relationships

prep for eventual SQLAlchemy 2.x
This commit is contained in:
Lance Edgar 2025-01-06 16:37:04 -06:00
parent 7e90888146
commit 4479d9ff91
2 changed files with 9 additions and 4 deletions

View file

@ -182,7 +182,6 @@ class BatchMixin:
Reference to the :class:`~wuttjamaican.db.model.auth.User` who Reference to the :class:`~wuttjamaican.db.model.auth.User` who
executed the batch. executed the batch.
""" """
@declared_attr @declared_attr
@ -231,7 +230,8 @@ class BatchMixin:
return orm.relationship( return orm.relationship(
User, User,
primaryjoin=lambda: User.uuid == cls.created_by_uuid, 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) executed = sa.Column(sa.DateTime(timezone=True), nullable=True)
@ -242,7 +242,8 @@ class BatchMixin:
return orm.relationship( return orm.relationship(
User, User,
primaryjoin=lambda: User.uuid == cls.executed_by_uuid, 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): def __repr__(self):
cls = self.__class__.__name__ cls = self.__class__.__name__
@ -404,12 +405,14 @@ class BatchRowMixin:
order_by=lambda: row_class.sequence, order_by=lambda: row_class.sequence,
collection_class=ordering_list('sequence', count_from=1), collection_class=ordering_list('sequence', count_from=1),
cascade='all, delete-orphan', cascade='all, delete-orphan',
cascade_backrefs=False,
back_populates='batch') back_populates='batch')
# now, here's the `BatchRow.batch` # now, here's the `BatchRow.batch`
return orm.relationship( return orm.relationship(
batch_class, batch_class,
back_populates='rows') back_populates='rows',
cascade_backrefs=False)
sequence = sa.Column(sa.Integer(), nullable=False) sequence = sa.Column(sa.Integer(), nullable=False)

View file

@ -52,6 +52,7 @@ class Upgrade(Base):
created_by = orm.relationship( created_by = orm.relationship(
'User', 'User',
foreign_keys=[created_by_uuid], foreign_keys=[created_by_uuid],
cascade_backrefs=False,
doc=""" doc="""
:class:`~wuttjamaican.db.model.auth.User` who created the :class:`~wuttjamaican.db.model.auth.User` who created the
upgrade record. upgrade record.
@ -82,6 +83,7 @@ class Upgrade(Base):
executed_by = orm.relationship( executed_by = orm.relationship(
'User', 'User',
foreign_keys=[executed_by_uuid], foreign_keys=[executed_by_uuid],
cascade_backrefs=False,
doc=""" doc="""
:class:`~wuttjamaican.db.model.auth.User` who executed the :class:`~wuttjamaican.db.model.auth.User` who executed the
upgrade. upgrade.