Skip to content

Render error to user if base path reserved [WHIT-2884]#10914

Merged
patrickpatrickpatrick merged 2 commits into
mainfrom
catch-base-path-exception-and-show-user
Jan 13, 2026
Merged

Render error to user if base path reserved [WHIT-2884]#10914
patrickpatrickpatrick merged 2 commits into
mainfrom
catch-base-path-exception-and-show-user

Conversation

@ChrisBAshton
Copy link
Copy Markdown
Contributor

@ChrisBAshton ChrisBAshton commented Dec 3, 2025

What

When trying to create a document that has an already reserved base path, catch the error and render an error with the title field on the new document form.

Further details

  • rework the exception capturing to delete the saved edition if the base path conflict occurs (otherwise the edition would still be created and the user could continue to edit it by accessing through the edition search)
  • display an error on the title field of the form as this is the field that determines the base path of a document

Why

Continues the work of #10912, now presenting an error to the user on the form instead of rendering a server error and removing the contents of the form.

Visual Differences

On attempting to create a new draft with the same base path:

Screenshot 2026-01-06 at 15 22 53

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

This application is owned by the Whitehall Experience team. Please let us know in #govuk-whitehall-experience-tech when you raise any PRs.

Follow these steps if you are doing a Rails upgrade.

@patrickpatrickpatrick patrickpatrickpatrick force-pushed the avoid-accidentally-overwriting-base-path branch from 3611a8f to 9de162c Compare December 8, 2025 11:44
Base automatically changed from avoid-accidentally-overwriting-base-path to main December 9, 2025 09:59
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch 2 times, most recently from f02d8a6 to 4383c4b Compare December 9, 2025 13:54
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch 10 times, most recently from a396a17 to 025310d Compare December 22, 2025 15:46
@patrickpatrickpatrick patrickpatrickpatrick changed the title WIP: Attempt to catch exception and show user error message Attempt to catch exception and show user error message Dec 23, 2025
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch 3 times, most recently from 5ddabe7 to 7e59046 Compare January 6, 2026 15:13
@patrickpatrickpatrick patrickpatrickpatrick changed the title Attempt to catch exception and show user error message Render error to user if base path reserved [WHIT-2884] Jan 6, 2026
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch 9 times, most recently from 519163d to ae69cf1 Compare January 7, 2026 11:45
@patrickpatrickpatrick patrickpatrickpatrick marked this pull request as ready for review January 7, 2026 11:46
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch from ae69cf1 to 8b7de83 Compare January 7, 2026 11:49
Copy link
Copy Markdown
Contributor Author

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for nudging this towards the finish line, @patrickpatrickpatrick ! Some comments below.

Comment thread features/news-article.feature Outdated
Comment thread app/models/edition.rb
Comment thread app/controllers/admin/editions_controller.rb
Comment thread test/functional/admin/standard_editions_controller_test.rb Outdated
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch 3 times, most recently from f2f3246 to 5088778 Compare January 8, 2026 14:43
@patrickpatrickpatrick patrickpatrickpatrick self-assigned this Jan 8, 2026
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch 2 times, most recently from 6ad354d to 14c4330 Compare January 9, 2026 12:17
Comment thread lib/whitehall/publishing_api.rb Outdated
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch from 14c4330 to 73f513b Compare January 12, 2026 13:41
Copy link
Copy Markdown
Contributor Author

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 one possible optimisation below.

I raised the PR, so can't approve it - so feel free to go ahead and merge it @patrickpatrickpatrick !

end

def self.ensure_base_path_is_associated_with_this_content_id!(base_path, content_id)
def self.ensure_base_path_is_associated_with_this_content_id!(instance, content)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified further I think? To just take instance? (And then use instance.base_path instead of content[:base_path]...?)

Copy link
Copy Markdown
Contributor

@patrickpatrickpatrick patrickpatrickpatrick Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, since content[:base_path] comes from the presenter of the instance and there's at least one instance of that being derived from presenter and not from the model.

patrickpatrickpatrick and others added 2 commits January 13, 2026 10:11
The user attempts to create a document with the same base path as a
published edition then destroy the newly saved edition. This is required
as the edition is saved before the conflict check. If the edition is not
destroyed then the user can still edit and attempt to save and/or force
publish the conflicting new edition.
Instead of presenting a server error to the user if they try and create
an edition that has the base path of another published edition, the
error is now presented to the user.
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the catch-base-path-exception-and-show-user branch from 73f513b to 85d0577 Compare January 13, 2026 10:11
@patrickpatrickpatrick patrickpatrickpatrick merged commit eabb594 into main Jan 13, 2026
25 checks passed
@patrickpatrickpatrick patrickpatrickpatrick deleted the catch-base-path-exception-and-show-user branch January 13, 2026 10:30
ChrisBAshton added a commit that referenced this pull request Jan 20, 2026
Reverts #10914. The PR did more than originally intended.

1. In #10912, we added a check to ensure that the generated base
   path of a document didn't already exist in Publishing API under
   a different content ID. We raised an exception in such cases.
   This was to accommodate the one or two cases where Whitehall
   has somehow produced a document that already exists under the
   same route in Publishing API, e.g. a 'legacy' News Article
   from several years ago, conflicting with a 'StandardEdition'
   News Article created recently. All such cases are resolved now.
2. In #10914, we intended to capture the exception and display it
   to the user, to offer a slightly more user friendly experience.
   However, the scope of the PR grew to include uniqueness checks
   on the *title* as well as the base path. We didn't anticipate
   any issues at the time.
3. There are over 12k documents in Whitehall that have clashing
   titles (or rather, have slugs that clash but for the fact that
   FriendlyId auto-increments the slug, e.g. `foo` and `foo--2`).
   The validation added in #10914 meant that already-published
   documents whose titles/slugs clash with other documents (when
   the 'sequence' suffix is dropped) could not have new drafts
   created. This has led to several support tickets.
4. We've been attempting to 'fix forward' this behaviour in #11003,
   to add the validation constraints *only* on 'first draft'
   editions, but there is a fair bit of complexity to consider.

In the short term, therefore, we've decided to roll back the
changes from #10914, to allow us a bit of breathing room to look
at the problem again more holistically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants