Repository: Cloud-CV/EvalAI

Issue:
Modify challenge phase query for displaying challenge phase detail
**Current Scenario:**
The function [here](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/views.py#L398) will **not** throw the error even if there are no challenge phase corresponding to the challenge.

**Steps to Reproduce:** You will only be able to check it only at the API level.
Let us suppose there exists a challenge with id 34 and phase ids 120, 121. Now when you will hit the [url ](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/urls.py#L17)with challenge id 34 and phase id say 1 then it won't give error if phase id 1 exists(for any other challenge). 

Ideally, it this [url](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/urls.py#L17) should only accept the phase ids 120 and 121 and should throw error for every other phase id.

**Deliverables:**
Modify the challenge phase query [here](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/views.py#L406) to include the `challenge` parameter in it.

What should be added:
`challenge_phase = ChallengePhase.objects.get(challenge=challenge, pk=pk)`
Also, Update the response message to
`response_data = {'error': 'Challenge Phase {} does not exist'.format(pk)}`
Modify challenge phase query for displaying challenge phase detail
**Current Scenario:**
The function [here](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/views.py#L398) will **not** throw the error even if there are no challenge phase corresponding to the challenge.

**Steps to Reproduce:** You will only be able to check it only at the API level.
Let us suppose there exists a challenge with id 34 and phase ids 120, 121. Now when you will hit the [url ](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/urls.py#L17)with challenge id 34 and phase id say 1 then it won't give error if phase id 1 exists(for any other challenge). 

Ideally, it this [url](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/urls.py#L17) should only accept the phase ids 120 and 121 and should throw error for every other phase id.

**Deliverables:**
Modify the challenge phase query [here](https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/views.py#L406) to include the `challenge` parameter in it.

What should be added:
`challenge_phase = ChallengePhase.objects.get(challenge=challenge, pk=pk)`
Also, Update the response message to
`response_data = {'error': 'Challenge Phase {} does not exist'.format(pk)}`


Discussion:
@RishabhJain2018 I would like to work up on this!
Sure @HargovindArora go ahead!
@RishabhJain2018 How to check whether the changes made are showing effect? I meant how should I reproduce error after making the required changes? I tried deleting the phases of the challenges already present there, nothing happened.
@HargovindArora I have updated the description.
I would like to start contributing by working on this !!
@rakesh-1601 Sounds good! Please let us know here or on our Gitter channel if you're having any difficulties. :)
@rakesh-1601 Please feel free to take up any other issue since @HargovindArora has already opened a PR for this.
Hello. Is this issue still open? Can I work on this?
@Arpitrf looks like #1751 is already there for this. Please feel free to take any other unassigned issue. 
@RishabhJain2018  I would like to work on it.
Sure!
Can I work on this issue @RishabhJain2018 ?

@kurianbenoy  There is already a PR opened for this issue which is yet to be reviewed.
> @kurianbenoy There is already a PR opened for this issue which is yet to be reviewed.

The travis tests for your PR is failing. That's why it's not being reviewed. 
@RishabhJain2018 I would like to work up on this!
Sure @HargovindArora go ahead!
@RishabhJain2018 How to check whether the changes made are showing effect? I meant how should I reproduce error after making the required changes? I tried deleting the phases of the challenges already present there, nothing happened.
@HargovindArora I have updated the description.
I would like to start contributing by working on this !!
@rakesh-1601 Sounds good! Please let us know here or on our Gitter channel if you're having any difficulties. :)
@rakesh-1601 Please feel free to take up any other issue since @HargovindArora has already opened a PR for this.
Hello. Is this issue still open? Can I work on this?
@Arpitrf looks like #1751 is already there for this. Please feel free to take any other unassigned issue. 
@RishabhJain2018  I would like to work on it.
Sure!
Can I work on this issue @RishabhJain2018 ?

@kurianbenoy  There is already a PR opened for this issue which is yet to be reviewed.
> @kurianbenoy There is already a PR opened for this issue which is yet to be reviewed.

The travis tests for your PR is failing. That's why it's not being reviewed. 

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -517,9 +517,9 @@ def challenge_phase_detail(request, challenge_pk, pk):
         return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
 
     try:
-        challenge_phase = ChallengePhase.objects.get(pk=pk)
+        challenge_phase = ChallengePhase.objects.get(challenge=challenge, pk=pk)
     except ChallengePhase.DoesNotExist:
-        response_data = {"error": "ChallengePhase does not exist"}
+        response_data = {"error": "Challenge phase {} does not exist for challenge {}".format(pk, challenge.pk)}
         return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
 
     if request.method == "GET":


Test patch:
diff --git a/tests/unit/challenges/test_views.py b/tests/unit/challenges/test_views.py
--- a/tests/unit/challenges/test_views.py
+++ b/tests/unit/challenges/test_views.py
@@ -2203,14 +2203,13 @@ def test_update_challenge_phase_when_user_is_its_creator(self):
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
     def test_particular_challenge_phase_does_not_exist(self):
-        self.url = reverse_lazy(
-            "challenges:get_challenge_phase_detail",
-            kwargs={
-                "challenge_pk": self.challenge.pk,
-                "pk": self.challenge_phase.pk + 2,
-            },
-        )
-        expected = {"error": "ChallengePhase does not exist"}
+        self.url = reverse_lazy('challenges:get_challenge_phase_detail',
+                                kwargs={'challenge_pk': self.challenge.pk,
+                                        'pk': self.challenge_phase.pk + 2})
+        expected = {
+            'error': 'Challenge phase {} does not exist for challenge {}'.format(
+                (self.challenge_phase.pk + 2), self.challenge.pk)
+        }
         response = self.client.get(self.url, {})
         self.assertEqual(response.data, expected)
         self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)