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

fix: repeated structured property containing blob property with legacy_data (#817) #946

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
🦉 Updates from OwlBot post-processor
  • Loading branch information
gcf-owl-bot[bot] committed Feb 13, 2024
commit 2f1ab13036df8f9748ac227e707c206cf68dde32
4 changes: 3 additions & 1 deletion google/cloud/ndb/model.py
Expand Up @@ -2653,7 +2653,9 @@ def _to_datastore(self, entity, data, prefix="", repeated=False):
data[key] = value
if not self._repeated:
values = [
zlib.compress(v) if v and not v.startswith(_ZLIB_COMPRESSION_MARKERS) else v
zlib.compress(v)
if v and not v.startswith(_ZLIB_COMPRESSION_MARKERS)
else v
for v in (value if repeated else [value])
]
value = values if repeated else values[0]
Expand Down
18 changes: 11 additions & 7 deletions tests/unit/test_model.py
Expand Up @@ -1805,17 +1805,24 @@ class ParentKind(model.Model):
compressed_value_one = zlib.compress(uncompressed_value_one)
uncompressed_value_two = b"xyz" * 1000
compressed_value_two = zlib.compress(uncompressed_value_two)
entity = ParentKind(foo=[ThisKind(bar=uncompressed_value_one), ThisKind(bar=uncompressed_value_two)])
entity = ParentKind(
foo=[
ThisKind(bar=uncompressed_value_one),
ThisKind(bar=uncompressed_value_two),
]
)
ds_entity = model._entity_to_ds_entity(entity)
assert "foo.bar" not in ds_entity._meanings
assert "foo.bar" in ds_entity.keys()
assert ds_entity.get("foo.bar") == [
compressed_value_one,
compressed_value_two
compressed_value_two,
]

@staticmethod
def test__to_datastore_legacy_compressed_repeated_in_parent_uninitialized(in_context):
def test__to_datastore_legacy_compressed_repeated_in_parent_uninitialized(
in_context,
):
class ThisKind(model.Model):
bar = model.BlobProperty(compressed=True, repeated=False)

Expand All @@ -1829,10 +1836,7 @@ class ParentKind(model.Model):
ds_entity = model._entity_to_ds_entity(entity)
assert "foo.bar" not in ds_entity._meanings
assert "foo.bar" in ds_entity.keys()
assert ds_entity.get("foo.bar") == [
None,
compressed_value
]
assert ds_entity.get("foo.bar") == [None, compressed_value]

@staticmethod
@pytest.mark.usefixtures("in_context")
Expand Down