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

ndb.key.urlsafe() should return a string not bytes #71

Closed
martin-green opened this issue Mar 17, 2023 · 4 comments · May be fixed by #72
Closed

ndb.key.urlsafe() should return a string not bytes #71

martin-green opened this issue Mar 17, 2023 · 4 comments · May be fixed by #72
Assignees

Comments

@martin-green
Copy link

Expected Behavior

When calling ndb.key.urlsafe() you should get a string that can be concatenated with other strings.

Actual Behavior

Currently it return bytes so you need to add .decode() on every call to urlsafe()

Steps to Reproduce the Problem

  1. On a ndb.Model derived class do: x.key.urlsafe() + ''
  2. this will generate a runtime error: TypeError: can only concatenate str (not "bytes") to str

Specifications

  • Version: 1.0.0
  • Platform: Ubuntu 20.04 (wsl2)
@spiqueras
Copy link

spiqueras commented May 24, 2023

Particularly annoying when serializing to JSON.

Will it remain a bytes object or will it be changed to str? If it's the former, I have some .decode()s to add.

@martin-green
Copy link
Author

It is very annoying. Without this you would have to change all templates with string variables (almost all).

@martin-green
Copy link
Author

@shreejad is this something that you could take? There is a PR: #72

@shreejad
Copy link
Collaborator

Hi, we had an internal discussion about this behavior, and we usually try to align with Cloud NDB. This would be a breaking change, so the barrier is high. I will discuss with the Cloud NDB team and post an update. For now, I don't see this change happening in the short term future.

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 a pull request may close this issue.

3 participants