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

feat: Key.to_legacy_urlsafe() #348

Merged
merged 4 commits into from
Mar 2, 2020
Merged

Conversation

chrisrossi
Copy link
Contributor

Workaround the fact that Google has deprecated the location prefix, but it is still required by the Google Datastore admin console, by allowing users to manually provide a location prefix when generating urlsafe keys.

Fixes #264.

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Feb 26, 2020
@chrisrossi
Copy link
Contributor Author

Hi @chmoder !

See note from Googlebot above. I cherry picked your commit.

Thanks!
Chris

@chmoder
Copy link
Contributor

chmoder commented Feb 27, 2020

@googlebot I consent.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Feb 27, 2020
@andrewsg
Copy link
Contributor

Thank you for your help, @chmoder!

@@ -739,6 +739,29 @@ def urlsafe(self):
raw_bytes = self.serialized()
return base64.urlsafe_b64encode(raw_bytes).strip(b"=")

def to_legacy_urlsafe(self, location_prefix=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

If this method has no use except to add the location prefix, we can make the location prefix non-optional.

@@ -739,6 +739,29 @@ def urlsafe(self):
raw_bytes = self.serialized()
return base64.urlsafe_b64encode(raw_bytes).strip(b"=")

def to_legacy_urlsafe(self, location_prefix=None):
"""A ``Reference`` protobuf serialized and encoded as urlsafe base 64.
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring suggestion:

    """A urlsafe serialized ``Reference`` protobuf with an App Engine prefix

    This will produce a urlsafe string which includes an App Engine location prefix ("partition"), compatible with the Google Datastore admin console.

    Arguments:
        location_prefix (str): A location prefix ("partition") to be prepended to the key's `project` when serializing the key. A typical value is "s~", but "e~" or other partitions are possible depending on the project's region and other factors.

@chrisrossi
Copy link
Contributor Author

@andrewsg Changes pushed.

Copy link
Contributor

@andrewsg andrewsg left a comment

Choose a reason for hiding this comment

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

Thanks!

@andrewsg andrewsg merged commit ab10e3c into googleapis:master Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

urlsafe ndb key is different than datastore admin
4 participants