opensafely-core / opensafely-core/opencodelists

Improve codelist update form behaviour when editing slugs

Open
#2,652 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement ui
Dominant language
Python
Stars
60
Forks
16
Avg merge
4d 12h
Merged PRs (30d)
17

Description

Why are we doing this?

The codelist_update view looks like it allows you to edit a codelist's name or slug or both:

Image

But it doesn't allow you to edit the slug without also editing the name. There is no indication of this prior to trying, it's not clear to the user why this isn't allowed, and the error message if you try to do so is incorrect. This is poor UX.

Image

This slug isn't used by this user (or anywhere) so it's not a "duplicate slug".

The view lives in codelists/views/codelist_update.py, is accessible through the URL pattern codelist/user/{username}/{codelist_slug}/edit/ which is linked on the Edit Metadata button, and invokes action update_codelist. There is code in update_codelist that attempts to handle different types of IntegrityError and determine why the new Handle can't be created, but it doesn't seem to handle at least this case as I expect.

From #1052: The cause is that changing the slug creates a new Handle (which allows us to redirect from the old slug to the new) -- but there's a database constraint that stops two handles belonging to the same owner from having the same name. We catch the IntegrityError, but misinterpret it. It's not clear to me that constraint is necessary.

How will we know when it's done?

The above issues are resolved.

What are we doing?

Options:

  • Relax the database constraint, allowing old Handle redirecting to new Handle with different slugs but the same name.
  • Clarify that slug change requires name change. Fix error handling / form UI.
  • Switch to automatic generation of slugs from the name that can't be edited by the user. This would also affect the API method of creating codelists.

Possibly "slug" is an unhelpful name for a generalist audience. Consider adding help_text to this form.


Defining delivery tasks guidance

Contributor guide

No contributing guide indexed for this repository

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

Start in codelists/views/codelist_update.py and trace the codelist/user/{username}/{codelist_slug}/edit/ flow to the update_codelist action in codelists/actions.py, especially its IntegrityError handling. Review the competing options and the existing Handle constraint before confirming the intended direction with maintainers. Done means the slug-editing UX and error behavior no longer misrepresent this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
full-stack
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.