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

Python: Implementation agnostic way to determine type of the elements of an empty repeated field #8529

Closed
busunkim96 opened this issue Apr 24, 2021 · 2 comments
Labels
inactive Denotes the issue/PR has not seen activity in the last 90 days. python

Comments

@busunkim96
Copy link
Contributor

What language does this apply to?

Python generated code

Describe the problem you are trying to solve.

There is no public method to determine the type of entries in an empty repeated field.

The proto-plus package wraps protobuf messages for many of the Python Google Cloud Client Libraries.
When a repeated field has no entries the proto-plus implementation deep-copies the whole message, adds an entry, and fetches the type of the field from that copy. The deep copying results in a performance hit.

Describe the solution you'd like

An implementation agnostic (works with both C++ and Python implementation types) way to determine type of the elements of an empty repeated field.

Describe alternatives you've considered

To try these examples, pip install googleapis-common-protos to get the built google.api.quota_pb2 proto. Proto file is here.

1. Add an entry to determine the type

This is what we're currently doing but would prefer not to, since we have to copy the whole message first.

>>> from google.api import quota_pb2
>>> q = quota_pb2.Quota()
>>> limit = q.limits.add()
>>> type(limit)
<class 'google.api.quota_pb2.QuotaLimit'>

2. Use _message_descriptor._concrete_class

This only works in the Python implementation and relies on private attributes.

>>> from google.api import quota_pb2
>>> q = quota_pb2.Quota()
>>> q.limits._message_descriptor._concrete_class
<class 'google.api.quota_pb2.QuotaLimit'>

In the C++ implementation the code above results in an error:

>>> q.limits._message_descriptor._concrete_class
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' object has no attribute '_message_descriptor'

Additional context

See googleapis/proto-plus-python#226 for additional context.

@elharo elharo added the python label Aug 25, 2021
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Feb 25, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Denotes the issue/PR has not seen activity in the last 90 days. python
Projects
None yet
Development

No branches or pull requests

2 participants