opensafely-core / job-server

A server for mediating jobs that can be run in an OpenSAFELY secure environment. q.v. job-runner
https://jobs.opensafely.org
Other
5 stars 10 forks source link

Workspace creation: a validation error causes the github repo field to be reset #4618

Open lucyb opened 3 weeks ago

lucyb commented 3 weeks ago

When creating a new workspace for a project, the GitHub repo field is reset when there is a validation error on form submission.

The other fields retain the values that have been entered, however the GitHub Repo field resets to the first item in the list. It's easy to miss that this has happened and not possible to change after the fact.

Steps to recreate:

  1. Enter a workspace name with a space or a hypen
  2. Enter a workspace purpose
  3. Select a repo from the list
  4. Click "Create workspace"

The form is refreshed with an error in the Workspace name, but all user entered values are the same, except for the GitHub repo.

Screenshot from 2024-09-19 17-43-21

Suggested fix:

  1. Ensure the selected repo is preserved when the clean_name step fails in the form.
  2. (Bonus) With a new form, default to selecting a blank value in the list, so that users always need to make a choice as selecting the first value by default is confusing.
iaindillingham commented 2 weeks ago

It looks as though^1 this bug has caused a user to create a workspace that's incorrectly associated with the .github repo 🙁

iaindillingham commented 1 week ago

In today's standup, I said I thought I'd found the source of this bug:

https://github.com/opensafely-core/job-server/blob/01352d0b3c4e1b72fe048b8748509d812cd2858a/jobserver/forms.py#L129

On closer inspection, I hadn't.