ChalmersGU-data-structure-courses / lab-system

Lab system and other scripts for grading and course administration (Canvas and GitLab integration). Currently used by the CSE department at Chalmers and GU for several courses, including data structures and algorithms.
0 stars 0 forks source link

Error creating projects when multiple students have the same name #20

Closed sattlerc closed 2 months ago

sattlerc commented 2 months ago

GitLab doesn't allow two projects with different path to have the same name. In an individual lab, the name of each student project consists of the student's name. Therefore, when two students have the same name, project creation will fail for the second student.

Note that the lab system doesn't otherwise use the project names. They are purely for display.

The error is:

  File "/home/lp1-data-structures/lab-system/group_project.py", line 754, in create
    project = self.lab.official_project.get.forks.create({
  File "/home/lp1-data-structures/.local/lib/python3.9/site-packages/gitlab/v4/objects/projects.py", line 1068, in create
    return cast(ProjectFork, CreateMixin.create(self, data, path=path, **kwargs))
  File "/home/lp1-data-structures/.local/lib/python3.9/site-packages/gitlab/exceptions.py", line 313, in wrapped_f
    raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabCreateError: 409: ['Project namespace name has already been taken', 'Name has already been taken']

The relevant log data:

2024-09-07 01:57:53 DEBUG http_logging: send: b'POST /api/v4/projects/17247/fork HTTP/1.1\r\nHost: git.chalmers.se\r\nUser-Agent: python-gitlab/3.1.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: glpat-syK-6pYyA46QN5T2sgbF\r\nContent-type: application/json\r\nContent-Length: 150\r\n\r\n'
2024-09-07 01:57:53 DEBUG http_logging: send: b'{"namespace_path": "courses/lp1-data-structures/2024/dat525/lab-1", "path": "lab1-[REDACTED]", "name": "Lab 1 \\u2014 Binary search \\u2014 [REDACTED]"}'
2024-09-07 01:57:54 DEBUG http_logging: reply: 'HTTP/1.1 409 Conflict\r\n'

Possible workaround: catch this exception (with matching error message) in group_project.py and retry with 2, 3, etc. appended to the name.

EDIT: redacted student name and CID.