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

don't try to update rep for the nil user #1384

Merged
merged 3 commits into from
Aug 25, 2024
Merged

Conversation

cellio
Copy link
Member

@cellio cellio commented Aug 23, 2024

A moderator tried to delete an answer by a deleted user and got a 500 error, specifically:

    NoMethodError: undefined method `reputation' for nil:NilClass
        user.update(reputation: user.reputation - Vote.total_rep_change(votes))
                                    ^^^^^^^^^^^

/var/apps/qpixel/app/models/post.rb:264:in `modify_author_reputation'
/var/apps/qpixel/app/controllers/posts_controller.rb:402:in `delete'

I added a guard against trying to change the rep for a deleted user. This might not be the best way to do it. Also, I was not able to reproduce the bug in a local dev environment, so it's possible this isn't really the cause of the error. But server errors are bad, so let's try to fix this one.

@cellio cellio requested review from ArtOfCode- and a team August 23, 2024 14:58
app/models/post.rb Outdated Show resolved Hide resolved
@cellio
Copy link
Member Author

cellio commented Aug 25, 2024

@Oaphi I applied @ArtOfCode- 's change. The key seems to have been destroyed (rather than deleted) accounts. After I 418ed myself and figured out how to do the db surgery to get back to a working dev environment, I think this works now.

@cellio cellio requested a review from Oaphi August 25, 2024 02:56
Copy link
Member

@Oaphi Oaphi left a comment

Choose a reason for hiding this comment

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

LGTM!

@Oaphi Oaphi merged commit 71a6eca into develop Aug 25, 2024
7 checks passed
@Oaphi Oaphi deleted the cellio/fix-500-on-delete branch August 25, 2024 03:26
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.

3 participants