Skip to content

Commit 59fc5af

Browse files
lantiuscguardia
andauthored
fix: Add support for 'name' Key instances to to_legacy_urlsafe (googleapis#420)
Co-authored-by: Carlos de la Guardia <cguardia@yahoo.com>
1 parent e303303 commit 59fc5af

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

google/cloud/ndb/key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def to_legacy_urlsafe(self, location_prefix):
759759
"""
760760
return google.cloud.datastore.Key(
761761
self._key.kind,
762-
self._key.id,
762+
self._key.id or self._key.name,
763763
namespace=self._key.namespace,
764764
project=self._key.project,
765765
).to_legacy_urlsafe(location_prefix=location_prefix)

tests/unit/test_key.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,15 @@ def test_to_legacy_urlsafe():
576576
== b"agNzfmZyBwsSAWQYeww"
577577
)
578578

579+
@staticmethod
580+
@pytest.mark.usefixtures("in_context")
581+
def test_to_legacy_urlsafe_name():
582+
key = key_module.Key("d", "x", app="f")
583+
assert (
584+
key.to_legacy_urlsafe(location_prefix="s~")
585+
== b"agNzfmZyCAsSAWQiAXgM"
586+
)
587+
579588
@staticmethod
580589
@pytest.mark.usefixtures("in_context")
581590
@mock.patch("google.cloud.ndb._datastore_api")

0 commit comments

Comments
 (0)