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

support query filters with urlsafe() ndb.Keys #9

Merged
merged 7 commits into from Oct 23, 2014

Conversation

soundofjw
Copy link
Contributor

Enables the filters parameter of the datastore input_readers to supply a urlsafe() copy of an ndb.Key for a ndb.KeyProperty.

This support is important for cases where ndb.Key is not properly being "JSONified," as it is transformed through pipelines.

An alternative user-end fix is to add ndb.Key JSONification through monkeypatching. This provides a more 'out of the box' solution for this seemingly common problem. - now included.

@soundofjw
Copy link
Contributor Author

It would be nice to see this also recreated with db.ReferenceProperty, in _validate_filters but I am not using db to test it.


def _JsonDecodeKey(d):
"""Json decode a ndb.Key object."""
k_c = d['key_string']
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use something more descriptive than k_c for the var.

Maybe encoded_key?

@soundofjw
Copy link
Contributor Author

@AngryBrock Done! Thanks for the feedback. :)

encoded_key = d['encoded_key']
if isinstance(encoded_key, (list, tuple)):
return ndb.Key(flat=encoded_key)
return ndb.Key(urlsafe=d['encoded_key'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for not being clear here. I mean on this line you should use the variable 'encoded_key' that you already set on line 103, rather than fetching it from 'd' again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh gosh, duh. thanks 👍

@AngryBrock
Copy link
Contributor

Thanks for contributing! Just one small nitpick I have and then I will approve this.

@soundofjw
Copy link
Contributor Author

All set. :)

@AngryBrock
Copy link
Contributor

Perfect, thanks!

AngryBrock added a commit that referenced this pull request Oct 23, 2014
support query filters with urlsafe() ndb.Keys
@AngryBrock AngryBrock merged commit ff5858a into GoogleCloudPlatform:master Oct 23, 2014
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.

None yet

2 participants