Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

feat: Key.to_legacy_urlsafe() - #348

Merged
andrewsg merged 4 commits into
googleapis:masterfrom
chrisrossi:fix-264
Mar 2, 2020
Merged

feat: Key.to_legacy_urlsafe()#348
andrewsg merged 4 commits into
googleapis:masterfrom
chrisrossi:fix-264

Conversation

@chrisrossi

Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Contributor Author

Hi @chmoder !

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

Thanks!
Chris

@chmoder

chmoder commented Feb 27, 2020

Copy link
Copy Markdown
Contributor

@googlebot I consent.

@googlebot

Copy link
Copy Markdown

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
Copy Markdown
Contributor

Thank you for your help, @chmoder!

Comment thread google/cloud/ndb/key.py Outdated
raw_bytes = self.serialized()
return base64.urlsafe_b64encode(raw_bytes).strip(b"=")

def to_legacy_urlsafe(self, location_prefix=None):

Copy link
Copy Markdown
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.

Comment thread google/cloud/ndb/key.py Outdated
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
Copy Markdown
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
Copy Markdown
Contributor Author

@andrewsg Changes pushed.

@andrewsg andrewsg left a comment

Copy link
Copy Markdown
Contributor

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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