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

AO3-6795 fix 500 error when excluding search param is invalid #4899

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AliceLoeser
Copy link
Contributor

@AliceLoeser AliceLoeser commented Aug 19, 2024

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-6795

Purpose

This PR fixes a bug that displayed a 500 error when the search is invalid, because @facets is nil since @works is invalid (has an error).

NoMethodError: undefined method `[]' for nil:NilClass

          @facets[tag.class.to_s.underscore] ||= []
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  app/controllers/works_controller.rb:123:in `block in index'
    @facets[tag.class.to_s.underscore] ||= []
  app/controllers/works_controller.rb:122:in `index'
    tags.each do |tag|

Testing Instructions

  • Go to a tag, e.g. Alternate Universe: https://test.archiveofourown.org/tags/Alternate Universe/works
  • In the filters, expand one of the sections for excluding a tag and choose something to exclude, e.g. the Not Rated rating
  • Also in the filters, enter something invalid in “Search within results,” e.g. otp: true, sort: words (the comma makes it invalid)
  • Press Sort and Filter
  • Notice that instead of the 500 error we see an error flash with "Your search failed because of a syntax error" message

Credit

AliceLsr (feminine pronouns)

@AliceLoeser AliceLoeser marked this pull request as ready for review August 20, 2024 08:39
@AliceLoeser AliceLoeser changed the title AO3-6795 fix 500 error when exclusing search param is invalid AO3-6795 fix 500 error when excluding search param is invalid Aug 20, 2024
Comment on lines +82 to +84
When I fill in "work_search_query" with "bad~query!!!"
And I press "Sort and Filter"
Then I should see "Your search failed because of a syntax error"
Copy link
Contributor

@Bilka2 Bilka2 Aug 22, 2024

Choose a reason for hiding this comment

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

This runs after the filters have been cleared, so this test passes even without the bug fix.

I think it would be good to make a separate scenario for the bad query with an excluded tag, this scenario is already pretty long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants