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

Sort out Query options. #60

Merged
merged 2 commits into from
Apr 5, 2019
Merged

Conversation

chrisrossi
Copy link
Contributor

Make use of the default_options argument to the Query
constructor. Make all arguments to Query.fetch explicit, and perform
the complicated dance of merging all the arguments and options to both
the Query constructor and Query.fetch into a single set of
options for passing to _datastore_query.fetch.

Make use of the ``default_options`` argument to the ``Query``
constructor. Make all arguments to ``Query.fetch`` explicit, and perform
the complicated dance of merging all the arguments and options to both
the ``Query`` constructor and ``Query.fetch`` into a single set of
options for passing to ``_datastore_query.fetch``.

class QueryOptions:
__slots__ = (
"client",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not used in NDB.


class QueryOptions:
__slots__ = (
"client",
# Query options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to organize these according to which ones are passed to the Query constructor and which ones are passed to Query.fetch. projection is passed to both.

if config is not None and not isinstance(config, QueryOptions):
raise TypeError("Config must be a QueryOptions instance.")

for key in self.__slots__:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored to avoid AttributeError when accessing an attribute that wasn't explicitly passed in.

default = getattr(config, key, None) if config else None
setattr(self, key, kwargs.get(key, default))

def __eq__(self, other):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To support unit tests.

@chrisrossi chrisrossi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2019
Copy link
Contributor

@cguardia cguardia left a comment

Choose a reason for hiding this comment

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

Looking good. Really a lot simpler than before.

@chrisrossi chrisrossi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2019
@chrisrossi chrisrossi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2019
@chrisrossi chrisrossi merged commit 7dfc776 into googleapis:master Apr 5, 2019
@chrisrossi chrisrossi deleted the query-options branch April 17, 2019 14:17
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.

None yet

3 participants