From 1e953e60ccbd3fed709687d2b92be04f29da630d Mon Sep 17 00:00:00 2001 From: ndu Date: Thu, 12 Dec 2024 09:36:20 +0100 Subject: [PATCH] chore(fix): add fix --- .../apps/research/serializers/article_serializer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/apps/research/serializers/article_serializer.py b/server/apps/research/serializers/article_serializer.py index 9ec5344..f041115 100644 --- a/server/apps/research/serializers/article_serializer.py +++ b/server/apps/research/serializers/article_serializer.py @@ -103,12 +103,13 @@ def validate_related_article_ids(self, value): if len(value) > 3: raise serializers.ValidationError("You can only have a maximum of 3 related articles.") + # Check for duplicates + article_ids = [article.id for article in value] + if len(article_ids) != len(set(article_ids)): + raise serializers.ValidationError("Duplicate articles are not allowed.") + article_id = self.instance.id if self.instance else None - if article_id is None: - request = self.context.get('request') - if request and hasattr(request, 'data'): - article_id = request.data.get('id') - + if article_id and article_id in [article.id for article in value]: raise serializers.ValidationError("An article cannot be related to itself.")