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 unbound var in search view #5794

Merged
merged 2 commits into from
Jun 12, 2019
Merged

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Jun 12, 2019

@@ -105,7 +100,7 @@ def elastic_search(request, project_slug=None):

# Make sure our selected facets are displayed even when they return 0 results
for avail_facet in ALL_FACETS:
value = getattr(user_input, avail_facet)
value = getattr(user_input, avail_facet, None)
Copy link
Member Author

Choose a reason for hiding this comment

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

if a default isn't given to getattr it raises an exception.


results = ''
results = None
Copy link
Member Author

Choose a reason for hiding this comment

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

This feels more like an object than an empty string

@stsewd stsewd requested review from ericholscher and a team June 12, 2019 05:00
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good to me.

I left just a question about the what to do when the user_input.type is not what we are expecting.

)

search = search_facets[user_input.type](
query=user_input.query, user=request.user, **kwargs
Copy link
Member

Choose a reason for hiding this comment

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

The solution with defaultdict is more readable to me, I like it. Although, there is a new logic hidden: if the type does not exist (for any reason) we are going to return ProjectSearch results. Is that OK? would be better to just return no results at all?

Copy link
Member

Choose a reason for hiding this comment

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

We may want to add another condition next to the user_input.query

... and (user_input.type in search_facets):

and remove the lambda from the defaultdict.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

👍

It seems we have the default set in multiples places then. I think we could just have only one.

@stsewd stsewd merged commit de0e916 into readthedocs:master Jun 12, 2019
@stsewd stsewd deleted the fix-unbound-var branch June 12, 2019 22:41
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