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

Bug fixes for search functionality #274

Merged
merged 1 commit into from
Jan 23, 2018

Conversation

NickolausDS
Copy link
Contributor

A bug in CRUD for both Search Subjects and Entries caused parameters
to be lost before the request was sent, resulting in errors from
Globus Search.

A bug in CRUD for both Search Subjects and Entries caused parameters
to be lost before the request was sent, resulting in errors from
Globus Search.
@sirosen
Copy link
Member

sirosen commented Jan 23, 2018

merge_params modifies a dict in place and returns None. You don't want to use x = merge_params(x, ...) -- the current usage is correct.

See the merge_params docstring and contents (which are quite small) for detail:

def merge_params(base_params, **more_params):
"""
Merge additional keyword arguments into a base dictionary of keyword
arguments. Only inserts additional kwargs which are not None.
This way, we can accept a bunch of named kwargs, a collector of additional
kwargs, and then put them together sensibly as arguments to another
function (typically BaseClient.get() or a variant thereof).
For example:
>>> def ep_search(self, filter_scope=None, filter_fulltext=None, **params):
>>> # Yes, this is a side-effecting function, it doesn't return a new
>>> # dict because it's way simpler to update in place
>>> merge_params(
>>> params, filter_scope=filter_scope,
>>> filter_fulltext=filter_fulltext)
>>> return self.get('endpoint_search', params=params)
this is a whole lot cleaner than the alternative form:
>>> def ep_search(self, filter_scope=None, filter_fulltext=None, **params):
>>> if filter_scope is not None:
>>> params['filter_scope'] = filter_scope
>>> if filter_fulltext is not None:
>>> params['filter_scope'] = filter_scope
>>> return self.get('endpoint_search', params=params)
the second form exposes a couple of dangers that are obviated in the first
regarding correctness, like the possibility of doing
>>> if filter_scope:
>>> params['filter_scope'] = filter_scope
which is wrong (!) because filter_scope='' is a theoretically valid,
real argument we want to pass.
The first form will also prove shorter and easier to write for the most
part.
"""
for param in more_params:
if more_params[param] is not None:
base_params[param] = more_params[param]

I'm going to close this out, since we don't want this patch, but please open an issue with the actual bug details so that we can dig into this.

@sirosen sirosen closed this Jan 23, 2018
@NickolausDS
Copy link
Contributor Author

#275

@sirosen
Copy link
Member

sirosen commented Jan 23, 2018

Oh, wow! Someone just pointed out to me that I got this totally wrong.
I thought you were changing good usage to bad, but you were changing bad usage to good!

@sirosen sirosen reopened this Jan 23, 2018
@sirosen
Copy link
Member

sirosen commented Jan 23, 2018

Yes, this looks correct, now that I take a closer look at it.
Sorry for the runaround.

There aren't any tests for this, so I'll go ahead and merge without waiting for the testsuite to run.

@sirosen sirosen merged commit b1f0ce2 into globus:master Jan 23, 2018
@NickolausDS
Copy link
Contributor Author

Thanks!

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