codalab / codalab/codabench

Bulk download results/submissions: dead code in `submissions.py`

Open Beginner friendly
#2,538 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Post-it
Dominant language
Python
Stars
176
Forks
74
Avg merge
5d 3h
Merged PRs (30d)
21

Description

@ObadaS @nicomy
The following PR:

  • #2001

Introduced useless lines of code in src/apps/api/views/submissions.py, in function download_many:

        for sub in submissions:
            file_path = sub.data.data_file.name.split('/')[-1]
            short_name = f"{sub.id}_{sub.owner}_PhaseId{sub.phase.id}_{sub.data.created_when.strftime('%Y-%m-%d:%M-%S')}_{file_path}"
            # url = sub.data.data_file.url
            url = SubmissionDetailSerializer(sub.data, context=self.get_serializer_context()).data['data_file']
            # url = SubmissionFilesSerializer(sub, context=self.get_serializer_context()).data['data_file']
            files.append({"name": short_name, "url": url})

        return Response(files)

        for sub in submissions:
            if sub.status not in [Submission.FINISHED]:  # Submission.FAILED, Submission.CANCELLED
                continue
            file_path = sub.data.data_file.name.split('/')[-1]
            complete_name = f"res_{sub.id}_{sub.owner}_PhaseId{sub.phase.id}_{sub.data.created_when.strftime('%Y-%m-%d:%M-%S')}_{file_path}"
            result_url = SubmissionDetailSerializer(sub.data, context=self.get_serializer_context()).get_scoring_result(sub)
            # detailed results is already in the results zip file but For very large detailed results it could be helpfull to remove it
            # detailed_result_url = serializer.get_scoring_result(sub)
            files.append({"name": complete_name, "url": result_url})

        return Response(files)

Everything that comes after the first return Response(files) will never be executed. It feels like another version of the same code, or under-progress version or something.

We can simply remove these lines, but I feel like there are interesting things that we can merge with the part above, like comments, the use of the prefix res_ in filename to avoid conflict between results and submissions, etc.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open src/apps/api/views/submissions.py and inspect download_many, especially the first return Response(files) and the unreachable second loop. Review PR #2001 to understand which version was intended, then confirm the endpoint’s expected response before removing or consolidating the dead implementation and its related comments.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.