Skip to content

Commit

Permalink
Backport: Fix deleting objects with comments (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Oct 26, 2022
1 parent f063214 commit 15ec01a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mwdb/model/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ class Object(db.Model):
"Attribute", backref="object", lazy=True, cascade="save-update, merge, delete"
)
comments = db.relationship(
"Comment",
backref="object",
lazy="dynamic",
cascade="save-update, merge, delete",
"Comment", backref="object", lazy="dynamic", passive_deletes=True
)
tags = db.relationship(
"Tag",
Expand All @@ -266,7 +263,10 @@ class Object(db.Model):
)

comment_authors = db.relationship(
"User", secondary="comment", back_populates="commented_objects"
"User",
secondary="comment",
back_populates="commented_objects",
passive_deletes=True,
)

shares = db.relationship(
Expand Down
13 changes: 13 additions & 0 deletions tests/backend/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,16 @@ def test_removing_objects(admin_session):

assert {"tag": "tag123"} in admin_session.get_tags(SampleB.dhash)


def test_removing_object_with_comments(admin_session):
testCase = RelationTestCase(admin_session)
sample = testCase.new_sample("Sample")
sample.create()

admin_session.add_comment(sample.dhash, "comment1")
admin_session.add_comment(sample.dhash, "comment2")
admin_session.add_comment(sample.dhash, "comment3")
admin_session.remove_object(sample.dhash)

with ShouldRaise(status_code=404):
admin_session.get_sample(sample.dhash)

0 comments on commit 15ec01a

Please sign in to comment.