aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorrr-2016-10-02 17:21:15 +0200
committerrr-2016-10-02 17:21:15 +0200
commitb853caf6f5d8c97f27a8026c31caf0a01759d6a3 (patch)
tree7c32ef127bb5e6cbbfb1f8591d97ebb2a59da3f0 /server
parentb0c50310011eaafd55956ddea4b2d37b3556fc7e (diff)
server/posts: fix relation updating
Fixes #103
Diffstat (limited to 'server')
-rw-r--r--server/szurubooru/func/posts.py7
-rw-r--r--server/szurubooru/tests/func/test_posts.py1
2 files changed, 7 insertions, 1 deletions
diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py
index 3863e5b..ee43b92 100644
--- a/server/szurubooru/func/posts.py
+++ b/server/szurubooru/func/posts.py
@@ -355,8 +355,13 @@ def update_post_tags(post, tag_names):
def update_post_relations(post, new_post_ids):
assert post
+ try:
+ new_post_ids = [int(id) for id in new_post_ids]
+ except ValueError:
+ raise InvalidPostRelationError(
+ 'A relation must be numeric post ID.')
old_posts = post.relations
- old_post_ids = [p.post_id for p in old_posts]
+ old_post_ids = [int(p.post_id) for p in old_posts]
new_posts = db.session \
.query(db.Post) \
.filter(db.Post.post_id.in_(new_post_ids)) \
diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py
index 56daaee..9c5ecd0 100644
--- a/server/szurubooru/tests/func/test_posts.py
+++ b/server/szurubooru/tests/func/test_posts.py
@@ -521,6 +521,7 @@ def test_update_post_relations_bidirectionality(post_factory):
db.session.flush()
post = post_factory()
posts.update_post_relations(post, [relation1.post_id, relation2.post_id])
+ db.session.flush()
posts.update_post_relations(relation1, [])
assert len(post.relations) == 1
assert post.relations[0].post_id == relation2.post_id

© 2015 - 2026 Jakob L. Kreuze