apache / apache/beam

Python io.gcp.datastore.v1new.types.Entity.to_client_entity does not handle list of Keys

Open
#20,702 0 comments 0 reactions 0 assignees View on GitHub
bug datastore io P3 python
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

in io.gcp.datastore.v1new.types, Entity's method `to_client_entity` does not do it's conversions for repeated properties (arrays)

I believe that changing the code of `to_client_entity` to the following should fix the issue

```

def _to_client_value(self, value)
if isinstance(value, Key):
if not value.project:
value.project
= self.key.project
value = value.to_client_key()
if isinstance(value, Entity):
if not value.key.project:

value.key.project = self.key.project
value = value.to_client_entity()
return value

def
to_client_entity(self):
"""
Returns a :class:`google.cloud.datastore.entity.Entity` instance that

represents this entity.
"""
res = entity.Entity(
key=self.key.to_client_key(),
exclude_from_indexes=tuple(self.exclude_from_indexes))

for name, value in self.properties.items():
if isinstance(value, list):
value = [self._to_client_value(item)
for item in value]
else:
value = self._to_client_value(value)
res[name] = value
return
res
```

 

Imported from Jira [BEAM-11441](https://issues.apache.org/jira/browse/BEAM-11441). Original Jira may contain additional context.
Reported by: alexindaco.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.