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

Raise exceptions when updates fail #2159

Merged
merged 1 commit into from
May 8, 2024
Merged

Conversation

richardTowers
Copy link
Contributor

In 000fbee we fixed a data issue which was causing two artefacts in publisher's database to fail to update.

There was effectively no visibility of this situation from the developers' perspective - only the user saw the error. We didn't get an error in sentry, a log message in logit, or even a 500 in the metrics.

The update method in mongoid returns false if the record can't be updated because it's not valid. We weren't checking the result and logging anything, so the failure was effectively silent.

Switching to update! will raise Errors::Validations if the record being updated is not valid. This will result in the user seeing a 500 / Something went wrong error page, instead of an validation-style message they can't do anything about. It will also mean we get an error in Sentry, and in logit, and there will be a 500 in our metrics.

Alternatively we could check the return value of update and log a warning, but I think this situation is genuinely an error, and it's better to raise.

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

In 000fbee we fixed a data issue which was causing two artefacts in
publisher's database to fail to update.

There was effectively no visibility of this situation from the
developers' perspective - only the user saw the error. We didn't get an
error in sentry, a log message in logit, or even a 500 in the metrics.

The [update](https://www.mongodb.com/docs/mongoid/master/api/Mongoid/Persistable/Updatable.html#update-instance_method)
method in mongoid returns false if the record can't be updated because
it's not valid. We weren't checking the result and logging anything, so
the failure was effectively silent.

Switching to [update!](https://www.mongodb.com/docs/mongoid/master/api/Mongoid/Persistable/Updatable.html#update!-instance_method)
will raise Errors::Validations if the record being updated is not valid.
This will result in the user seeing a 500 / Something went wrong error
page, instead of an validation-style message they can't do anything
about. It will also mean we get an error in Sentry, and in logit, and
there will be a 500 in our metrics.

Alternatively we could check the return value of `update` and log a
warning, but I think this situation is genuinely an error, and it's
better to raise.
Copy link
Contributor

@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.

Makes sense to me 👍

Copy link
Contributor

@KludgeKML KludgeKML left a comment

Choose a reason for hiding this comment

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

Sounds good

@mtaylorgds
Copy link
Contributor

I think that makes sense. Is it worth capturing that behaviour in a test?

@richardTowers
Copy link
Contributor Author

richardTowers commented May 3, 2024

Thanks folks! I don't think it's worth a test, as there are lots of places where we call e.g. save!, and we don't test the exceptions in every case. I was glad to see that the existing tests didn't break, even though this codepath is almost certainly covered.

I think I'll wait until Monday to merge this, just in case I'm wrong about this being a rare situation 😅

@richardTowers richardTowers merged commit fff1d13 into main May 8, 2024
17 checks passed
@richardTowers richardTowers deleted the log-validation-errors branch May 8, 2024 12:33
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.

4 participants