[PATCH] Explicitly distinguish between comments on patch and cover

vkabatov at redhat.com vkabatov at redhat.com
Thu May 3 20:55:16 AEST 2018


From: Veronika Kabatova <vkabatov at redhat.com>

reverse() gets confused when the same view name and kwargs are passed to
it, ignoring what endpoint the request originated from. Fix this by
using different view names for cover letter and patch comments views.

Reported-by: Daniel Axtens <dja at axtens.net>
Signed-off-by: Veronika Kabatova <vkabatov at redhat.com>
---
 patchwork/api/cover.py              | 2 +-
 patchwork/api/patch.py              | 2 +-
 patchwork/tests/api/test_comment.py | 4 ++--
 patchwork/urls.py                   | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py
index 7c80064..99cf9e6 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -46,7 +46,7 @@ class CoverLetterListSerializer(BaseHyperlinkedModelSerializer):
 
     def get_comments(self, cover):
         return self.context.get('request').build_absolute_uri(
-            reverse('api-comment-list', kwargs={'pk': cover.id}))
+            reverse('api-cover-comment-list', kwargs={'pk': cover.id}))
 
     class Meta:
         model = CoverLetter
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index d1931c0..028d685 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -94,7 +94,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
 
     def get_comments(self, patch):
         return self.context.get('request').build_absolute_uri(
-            reverse('api-comment-list', kwargs={'pk': patch.id}))
+            reverse('api-patch-comment-list', kwargs={'pk': patch.id}))
 
     def get_check(self, instance):
         return instance.combined_check_state
diff --git a/patchwork/tests/api/test_comment.py b/patchwork/tests/api/test_comment.py
index 9cad2ad..f79ea46 100644
--- a/patchwork/tests/api/test_comment.py
+++ b/patchwork/tests/api/test_comment.py
@@ -46,7 +46,7 @@ class TestCoverComments(APITestCase):
             kwargs['version'] = version
         kwargs['pk'] = cover.id
 
-        return reverse('api-comment-list', kwargs=kwargs)
+        return reverse('api-cover-comment-list', kwargs=kwargs)
 
     def assertSerialized(self, comment_obj, comment_json):
         self.assertEqual(comment_obj.id, comment_json['id'])
@@ -85,7 +85,7 @@ class TestPatchComments(APITestCase):
             kwargs['version'] = version
         kwargs['pk'] = patch.id
 
-        return reverse('api-comment-list', kwargs=kwargs)
+        return reverse('api-patch-comment-list', kwargs=kwargs)
 
     def assertSerialized(self, comment_obj, comment_json):
         self.assertEqual(comment_obj.id, comment_json['id'])
diff --git a/patchwork/urls.py b/patchwork/urls.py
index 1dc4ffc..e90de6b 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -283,10 +283,10 @@ if settings.ENABLE_REST_API:
     api_1_1_patterns = [
         url(r'^patches/(?P<pk>[^/]+)/comments/$',
             api_comment_views.CommentList.as_view(),
-            name='api-comment-list'),
+            name='api-patch-comment-list'),
         url(r'^covers/(?P<pk>[^/]+)/comments/$',
             api_comment_views.CommentList.as_view(),
-            name='api-comment-list'),
+            name='api-cover-comment-list'),
     ]
 
     urlpatterns += [
-- 
2.13.6



More information about the Patchwork mailing list