Closed ihsaan-ullah closed 1 month ago
@Didayolo this PR is ready for review. Please ignore the documentation comment, I will complete the documentation later when other task related features are added.
@ihsaan-ullah This test failed:
FAILED src/apps/api/tests/test_tasks.py::TestTasks::test_task_shown_as_validated_properly
_______________ TestTasks.test_task_shown_as_validated_properly ________________
self = <api.tests.test_tasks.TestTasks testMethod=test_task_shown_as_validated_properly>
def test_task_shown_as_validated_properly(self):
user = UserFactory(username='test')
solution = SolutionFactory(md5="12345")
task = TaskFactory(created_by=user, solutions=[solution])
competition = CompetitionFactory(created_by=user)
phase = PhaseFactory(competition=competition, tasks=[task])
submission = SubmissionFactory(md5="12345", phase=phase, status=Submission.FINISHED)
url = reverse('task-detail', kwargs={'pk': task.id})
self.client.login(username=user.username, password='test')
# task should be validated because we have a successful submission matching
# our solution
resp = self.client.get(url)
assert resp.status_code == 200
assert resp.data["validated"]
# make submission anything but Submission.FINISHED, task -> invalidated
submission.status = Submission.FAILED
submission.save()
resp = self.client.get(url)
assert resp.status_code == 200
> assert not resp.data["validated"]
E AssertionError: assert not True
src/apps/api/tests/test_tasks.py:30: AssertionError
----------------------------- Captured stdout call -----------------------------
This solution has no data associated with it...might be a test
This solution has no data associated with it...might be a test
This test is failing because of a change I made on this line in Task Serializer:
on this line task.validated
was checked BUT task has no property named validated
. Task model has a filed named _validated
We need to discuss this validation of task in the next meeting so that I can fix the test
@ihsaan-ullah
If the task validation code is not really related:
validated
fieldTask validation problem is shifted to #1078
Documentation added here: https://github.com/codalab/codabench/wiki/Public-Tasks-and-Tasks-Sharing and also added in the FAQs here
Trying to update a task:
codabench-django-1 | Internal Server Error: /api/tasks/72/
codabench-django-1 | Traceback (most recent call last):
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner
codabench-django-1 | response = get_response(request)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 115, in _get_response
codabench-django-1 | response = self.process_exception_by_middleware(e, request)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
codabench-django-1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
codabench-django-1 | return view_func(*args, **kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 116, in view
codabench-django-1 | return self.dispatch(request, *args, **kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 495, in dispatch
codabench-django-1 | response = self.handle_exception(exc)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 455, in handle_exception
codabench-django-1 | self.raise_uncaught_exception(exc)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 492, in dispatch
codabench-django-1 | response = handler(request, *args, **kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/mixins.py", line 84, in partial_update
codabench-django-1 | return self.update(request, *args, **kwargs)
codabench-django-1 | File "/app/src/apps/api/views/tasks.py", line 126, in update
codabench-django-1 | return Response(task_detail_serializer.data)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 563, in data
codabench-django-1 | ret = super(Serializer, self).data
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 262, in data
codabench-django-1 | self._data = self.to_representation(self.instance)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 530, in to_representation
codabench-django-1 | ret[field.field_name] = field.to_representation(attribute)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 1893, in to_representation
codabench-django-1 | return method(value)
codabench-django-1 | File "/app/src/apps/api/serializers/tasks.py", line 127, in get_validated
codabench-django-1 | return task.validated is not None
codabench-django-1 | AttributeError: 'Task' object has no attribute 'validated'
codabench-django-1 | Internal Server Error: /api/tasks/72/
codabench-django-1 | Traceback (most recent call last):
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner
codabench-django-1 | response = get_response(request)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 115, in _get_response
codabench-django-1 | response = self.process_exception_by_middleware(e, request)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
codabench-django-1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
codabench-django-1 | return view_func(*args, **kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 116, in view
codabench-django-1 | return self.dispatch(request, *args, **kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 495, in dispatch
codabench-django-1 | response = self.handle_exception(exc)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 455, in handle_exception
codabench-django-1 | self.raise_uncaught_exception(exc)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 492, in dispatch
codabench-django-1 | response = handler(request, *args, **kwargs)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/mixins.py", line 84, in partial_update
codabench-django-1 | return self.update(request, *args, **kwargs)
codabench-django-1 | File "/app/src/apps/api/views/tasks.py", line 126, in update
codabench-django-1 | return Response(task_detail_serializer.data)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 563, in data
codabench-django-1 | ret = super(Serializer, self).data
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 262, in data
codabench-django-1 | self._data = self.to_representation(self.instance)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 530, in to_representation
codabench-django-1 | ret[field.field_name] = field.to_representation(attribute)
codabench-django-1 | File "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 1893, in to_representation
codabench-django-1 | return method(value)
codabench-django-1 | File "/app/src/apps/api/serializers/tasks.py", line 127, in get_validated
codabench-django-1 | return task.validated is not None
codabench-django-1 | AttributeError: 'Task' object has no attribute 'validated'
Solved the issue by using correct serializer TaskSerializer
instead of TaskDetailSerializer
. Also updated the problematic function to not raise this issue again
@ mention of reviewers
@Didayolo
A brief description of the purpose of the changes contained in this PR.
This PR solves all the issues related to making tasks public and using them in competitions either by owners or other users. The following changes are made to enable this functionality.
key
present. That was not needed and is now removedTaskListSerializer
to properly use validated status and sharedwith list. Now that is fixed.TaskListSerializer
to show a checkmark in the tasks list table.Show public tasks
was checked but when this public task was clicked, details were not shown because it was not permitted from the backend. Now the backend is updated to return details for public tasks.Issues this PR resolves
1578
A checklist for hand testing
user 1
create a task and make it public using the task detail interface. Make sure that you can make the task public and privateuser 2
go to Resource interface -> Tasks tab, click show public tasks checkbox. Check that the task made public byuser 1
is shown here. Check that you can click the task and check its detailsuser 2
create a competition, go to edit competition->Phases. In one phase search the same task in the task dropdown and check that you can select this task for your phase and save changes.Checklist