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

[#57664] ActiveRecord::RecordNotFound in ActivitiesController#index #16688

Merged

Conversation

ba1ash
Copy link
Member

@ba1ash ba1ash commented Sep 10, 2024

Ticket

https://community.openproject.org/work_packages/57664

What are you trying to accomplish?

Fix error when viewing inactive user activity.

#determine_author can raise ActiveRecord::RecordNotFound if user does not exist or is inactive. Use rescue_from to catch it and send appropriate response.

Screenshots

image

What approach did you choose and why?

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@ba1ash ba1ash requested a review from cbliard September 10, 2024 09:47
@ba1ash ba1ash self-assigned this Sep 10, 2024
@ba1ash ba1ash requested a review from a team September 10, 2024 09:48
@ba1ash ba1ash removed the request for review from cbliard September 10, 2024 09:51
Copy link
Member

@cbliard cbliard 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 the fix. I have a few remarks.

The PR description is lacking explanations, making it harder to review. It could make it even harder for any future developer stumbling upon it. Same for the commit message, it's not helpful. It should describe what you fixed and why. The screenshot is not helpful as well: I thought it was the error happening before the fix. Just a label saying "After fix" would have helped.

If I understand correctly, the user is fetched in #determine_author. It looks up only active users. If the user is inactive (locked for instance), then the method will raise an ActiveRecord::RecordNotFound error. The index action is intended to catch it, but it can't work outside of this method. determine_author being called in a before action, that's why it's not caught.

You fixed it by using rescue_from helper which works in action AND in action hooks, fixing the issue.

Here is a proposal for the commit message:

Fix error when viewing inactive user activity

`#determine_author` can raise `ActiveRecord::RecordNotFound` if user does not
exist or is inactive. Use `rescue_from` to catch it and send appropriate
response.

Fixes https://community.openproject.org/wp/57664
Fixes https://appsignal.com/openproject-gmbh/sites/66b224a4d30d867bed8a1772/exceptions/incidents/461

Can you also modify your test to test against an inactive user instead of a non-existing user id?

Also this is not a critical bug and it's not a regression either, so it should target current dev branch.

Comment on lines 105 to 110
describe "with not existent user_id" do
it "renders 404" do
get "index", params: { project_id: project.id, user_id: 123123123 }
expect(response).to have_http_status(:not_found)
expect(response).to render_template "common/error"
end
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test with an inactive user instead? It would better reflect what happened in production.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, of course.

@ba1ash
Copy link
Member Author

ba1ash commented Sep 10, 2024

@cbliard Thanks for your review!
Sure, I can do it.

@ba1ash ba1ash force-pushed the bug/57664-activerecordrecordnotfound-in-activitiescontrollerindex branch from 007fe56 to dba9f10 Compare September 10, 2024 11:28
@ba1ash ba1ash requested a review from cbliard September 10, 2024 11:28
Copy link
Member

@cbliard cbliard 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 the changes.

It still needs to target dev and not release/14.5 because it's not a critical bug nor a regression. Even if there should be no issue with it that's how we agreed to work for bugs.

@ba1ash ba1ash changed the base branch from release/14.5 to dev September 10, 2024 12:03
@ba1ash ba1ash force-pushed the bug/57664-activerecordrecordnotfound-in-activitiescontrollerindex branch from dba9f10 to 5690f52 Compare September 10, 2024 12:13
`#determine_author` can raise `ActiveRecord::RecordNotFound` if user does not
exist or is inactive. Use `rescue_from` to catch it and send appropriate
response.

Fixes https://community.openproject.org/wp/57664
Fixes https://appsignal.com/openproject-gmbh/sites/66b224a4d30d867bed8a1772/exceptions/incidents/461

Co-authored-by: Christophe Bliard <[email protected]>
@ba1ash ba1ash force-pushed the bug/57664-activerecordrecordnotfound-in-activitiescontrollerindex branch from 5690f52 to e7a482d Compare September 10, 2024 12:14
Copy link
Member

@cbliard cbliard left a comment

Choose a reason for hiding this comment

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

Nice! Thanks a lot for bringing it in.

@ba1ash ba1ash merged commit 2dce32c into dev Sep 10, 2024
10 of 11 checks passed
@ba1ash ba1ash deleted the bug/57664-activerecordrecordnotfound-in-activitiescontrollerindex branch September 10, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants