From a22fe306d112707fe024da2e7788aef7566e7773 Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 31 Aug 2016 22:49:45 +0200 Subject: [PATCH] server/posts: fix deleting posts with relations --- server/szurubooru/db/post.py | 3 ++- server/szurubooru/tests/db/test_post.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/szurubooru/db/post.py b/server/szurubooru/db/post.py index 65942d37..8be7e8b5 100644 --- a/server/szurubooru/db/post.py +++ b/server/szurubooru/db/post.py @@ -176,7 +176,8 @@ class Post(Base): 'Post', secondary='post_relation', primaryjoin=post_id == PostRelation.parent_id, - secondaryjoin=post_id == PostRelation.child_id, lazy='joined') + secondaryjoin=post_id == PostRelation.child_id, lazy='joined', + backref='related_by') features = relationship( 'PostFeature', cascade='all, delete-orphan', lazy='joined') scores = relationship( diff --git a/server/szurubooru/tests/db/test_post.py b/server/szurubooru/tests/db/test_post.py index f0cf7a82..c0213535 100644 --- a/server/szurubooru/tests/db/test_post.py +++ b/server/szurubooru/tests/db/test_post.py @@ -78,16 +78,16 @@ def test_cascade_deletions( post.tags.append(tag1) post.tags.append(tag2) post.relations.append(related_post1) - post.relations.append(related_post2) + related_post2.relations.append(post) post.scores.append(score) post.favorited_by.append(favorite) post.features.append(feature) post.notes.append(note) - db.session.flush() + db.session.commit() assert not db.session.dirty assert post.user is not None and post.user.user_id is not None - assert len(post.relations) == 2 + assert len(post.relations) == 1 assert db.session.query(db.User).count() == 1 assert db.session.query(db.Tag).count() == 2 assert db.session.query(db.Post).count() == 3