-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix unbound var in search view #5794
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
Conversation
search can end up unbound if there isn't a valid facet Fix https://sentry.io/organizations/read-the-docs/issues/1054512234/?project=148442&query=is%3Aunresolved
@@ -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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
search can end up unbound if there isn't a valid facet
Fix https://sentry.io/organizations/read-the-docs/issues/1054512234/?project=148442&query=is%3Aunresolved