-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Public tasks -- updates to ensure public tasks can be viewed and used #1581
Conversation
…g task public/private buttion. Updated task update method to enable updating is_public status. Once a task is_public was updated, the response was not serialized, now fixed. Removed key from the task detail serializer. Modified validated and shared with methods to return correct responses. Added is_public to TaskListSerializer to show checkmark in the tasks list table.
…ls from other users
@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. |
Rebase public_tasks (#1588)
@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: codabench/src/apps/api/serializers/tasks.py Line 126 in de55ef3
on this line Task model: codabench/src/apps/tasks/models.py Line 30 in de55ef3
We need to discuss this validation of task in the next meeting so that I can fix the test |
If the task validation code is not really related:
|
Task 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' |
…tion updated to not raise error in the future
Solved the issue by using correct serializer |
@ 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
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