aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHunternif2019-04-23 01:46:35 +0700
committerHunternif2019-04-23 01:46:35 +0700
commitf020db29d17e2c34d1776132532828553277639a (patch)
tree3da0bd7a40cf1a0d43f18b8b3708b1bc4e89d096
parent20133cea01f407eb44b8ede5474d05b1d4cca02d (diff)
server: forbid merging tags with metrics
-rw-r--r--server/szurubooru/func/tags.py2
-rw-r--r--server/szurubooru/tests/func/test_tags.py16
2 files changed, 18 insertions, 0 deletions
diff --git a/server/szurubooru/func/tags.py b/server/szurubooru/func/tags.py
index 2c37be5..c6e2ab9 100644
--- a/server/szurubooru/func/tags.py
+++ b/server/szurubooru/func/tags.py
@@ -235,6 +235,8 @@ def merge_tags(source_tag: model.Tag, target_tag: model.Tag) -> None:
assert target_tag
if source_tag.tag_id == target_tag.tag_id:
raise InvalidTagRelationError('Cannot merge tag with itself.')
+ if source_tag.metric or target_tag.metric:
+ raise InvalidTagRelationError('Cannot merge tags with metrics.')
def merge_posts(source_tag_id: int, target_tag_id: int) -> None:
alias1 = model.PostTag
diff --git a/server/szurubooru/tests/func/test_tags.py b/server/szurubooru/tests/func/test_tags.py
index ba27d2a..23d6c9b 100644
--- a/server/szurubooru/tests/func/test_tags.py
+++ b/server/szurubooru/tests/func/test_tags.py
@@ -288,6 +288,22 @@ def test_merge_tags_with_itself(tag_factory):
tags.merge_tags(source_tag, source_tag)
+def test_merge_tags_with_metrics(tag_factory, metric_factory):
+ tag_with_metric1 = tag_factory()
+ tag_with_metric2 = tag_factory()
+ tag_no_metric = tag_factory()
+ tag_with_metric1.metric = metric_factory()
+ tag_with_metric2.metric = metric_factory()
+ db.session.add_all([tag_no_metric, tag_with_metric1, tag_with_metric2])
+ db.session.flush()
+ with pytest.raises(tags.InvalidTagRelationError):
+ tags.merge_tags(tag_no_metric, tag_with_metric2)
+ with pytest.raises(tags.InvalidTagRelationError):
+ tags.merge_tags(tag_with_metric1, tag_no_metric)
+ with pytest.raises(tags.InvalidTagRelationError):
+ tags.merge_tags(tag_with_metric1, tag_with_metric2)
+
+
def test_merge_tags_moves_usages(tag_factory, post_factory):
source_tag = tag_factory(names=['source'])
target_tag = tag_factory(names=['target'])

© 2015 - 2026 Jakob L. Kreuze