Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delete all routes journey #1774

Merged
merged 4 commits into from
Feb 13, 2025
Merged

Fix delete all routes journey #1774

merged 4 commits into from
Feb 13, 2025

Conversation

lfdebrux
Copy link
Member

@lfdebrux lfdebrux commented Feb 13, 2025

What problem does this pull request solve?

Trello card: https://trello.com/c/cFZnCzve/2127-bug-delete-all-routes-redirects-to-a-page-not-found-error

Currently when a user tries to delete all routes for a question they are shown a page not found error rather being redirected to the "Add and edit questions" page as expected.

I think this is happening because of a change in forms-api that means deleting a condition can also delete secondary skip conditions in the same request (alphagov/forms-api#686).

This PR adds a test that simulates the behaviour of forms-api currently, and changes the destroy methods for each repository so that trying to delete a condition that has already been deleted doesn't result in an exception. This behaviour is closer to how ActiveRecord behaves, and fixes the problem so that users won't see the error page any more.

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Has all relevant documentation been updated?

Copy link
Contributor

@thomasiles thomasiles left a comment

Choose a reason for hiding this comment

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

Fixing it across all the repositories is a really nice idea 👏

This specs for ConditionRepository#destroy have expectations on the
condition ids, but weren't setting ids on the condition objects
themselves.
We've found that in production the "delete all routes" journey has
stopped working properly; after the user confirms that they want to
delete all routes for a question, they see an error page rather than
being redirected to the "add and edit questions" page as expected.

Debugging locally revealed this is an unintended side-effect of an
unrelated change in forms-api, in PR alphagov/forms-api#686, which
changes the conditions model to delete secondary skip routes when a
skip route is deleted.

Because the process to delete all routes deletes the primary condition
before the secondary skip, when it comes to delete the secondary skip
that no longer exists, and the API responds with a 404. This 404 is then
parlayed by ActiveResource into a ResourceNotFound exception, which then
bubbles up to the Rails middleware, and is treated as a record not found
error, and Rails renders a 404 error page.

This commit adds a test that simulates this interaction, so we can make
some changes in our system to handle the scenario better.
…ready been deleted

`ActiveRecord::Persistence#destroy` does not raise an error if a record
has already been deleted, let's change our repository `destroy` methods
to behave in the same way.
@lfdebrux lfdebrux force-pushed the ldeb-fix-destroy-routes branch from 59343d5 to ec550fd Compare February 13, 2025 13:54
@lfdebrux lfdebrux enabled auto-merge February 13, 2025 13:55
@lfdebrux lfdebrux merged commit 7594352 into main Feb 13, 2025
4 checks passed
@lfdebrux lfdebrux deleted the ldeb-fix-destroy-routes branch February 13, 2025 13:59
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