Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 293456e

Browse filesBrowse files
author
Chris Rossi
authored
fix: correctly decode falsy values in legacy protocol buffers (#628)
Fixes #625
1 parent 60dbb38 commit 293456e
Copy full SHA for 293456e

File tree

Expand file treeCollapse file tree

2 files changed

+18
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-7
lines changed
Open diff view settings
Collapse file

‎packages/google-cloud-ndb/google/cloud/ndb/_legacy_entity_pb.py‎

Copy file name to clipboardExpand all lines: packages/google-cloud-ndb/google/cloud/ndb/_legacy_entity_pb.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def entity_props(self):
794794
for prop in self.property_list():
795795
name = prop.name().decode("utf-8")
796796
entity_props[name] = (
797-
prop.has_value() and self._get_property_value(prop.value()) or None
797+
self._get_property_value(prop.value()) if prop.has_value() else None
798798
)
799799
return entity_props
800800

Collapse file

‎packages/google-cloud-ndb/tests/system/test_misc.py‎

Copy file name to clipboardExpand all lines: packages/google-cloud-ndb/tests/system/test_misc.py
+17-6Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,24 @@ def test_query():
459459

460460
@pytest.mark.usefixtures("client_context")
461461
def test_legacy_local_structured_property_with_boolean(ds_entity):
462-
"""Regression test for #623
462+
"""Regression test for #623, #625
463463
464464
https://github.com/googleapis/python-ndb/issues/623
465+
https://github.com/googleapis/python-ndb/issues/625
465466
"""
466467
children = [
467468
b"x\x9c\xab\xe2\x96bNJ,R`\xd0b\x12`\xac\x12\xe1\xe0\x97bN\xcb\xcf\x07r9\xa5"
468-
b"\xd832\x15r\xf3s\x15\x01u_\x07\n"
469+
b"\xd832\x15r\xf3s\x15\x01u_\x07\n",
470+
b"x\x9c\xab\xe2\x96bNJ,R`\xd0b\x12`\xa8\x12\xe7\xe0\x97bN\xcb\xcf\x07ry\xa4"
471+
b"\xb82Rsr\xf2\x15R\x12S\x14\x01\x8e\xbf\x085",
469472
]
473+
470474
entity_id = test_utils.system.unique_resource_id()
471475
ds_entity(KIND, entity_id, children=children)
472476

473477
class OtherKind(ndb.Model):
474478
foo = ndb.StringProperty()
475-
bar = ndb.BooleanProperty(default=True)
479+
bar = ndb.BooleanProperty(required=True, default=True)
476480

477481
class SomeKind(ndb.Model):
478482
children = ndb.LocalStructuredProperty(
@@ -481,12 +485,19 @@ class SomeKind(ndb.Model):
481485

482486
entity = SomeKind.get_by_id(entity_id)
483487

484-
assert len(entity.children) == 1
488+
assert len(entity.children) == 2
485489
assert entity.children[0].foo == "hi mom!"
486490
assert entity.children[0].bar is True
491+
assert entity.children[1].foo == "hello dad!"
492+
assert entity.children[1].bar is False
487493

488-
entity.children[0].foo = "hello dad!"
494+
entity.children.append(OtherKind(foo="i'm in jail!", bar=False))
489495
entity.put()
490496

491497
entity = SomeKind.get_by_id(entity_id)
492-
assert entity.children[0].foo == "hello dad!"
498+
assert entity.children[0].foo == "hi mom!"
499+
assert entity.children[0].bar is True
500+
assert entity.children[1].foo == "hello dad!"
501+
assert entity.children[1].bar is False
502+
assert entity.children[2].foo == "i'm in jail!"
503+
assert entity.children[2].bar is False

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.