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

Error When Appending Enum to Repeated Field #201

Closed
BenRKarl opened this issue Mar 3, 2021 · 2 comments
Closed

Error When Appending Enum to Repeated Field #201

BenRKarl opened this issue Mar 3, 2021 · 2 comments
Assignees
Labels
P1 An important bug triage me I really want to be triaged.

Comments

@BenRKarl
Copy link

BenRKarl commented Mar 3, 2021

This issue appears to be a side effect of the bug fixes released in 1.14.2 as it isn't an issue in previous versions.

For context, all the Enums in our API are structured like this, i.e. an outer message and inner enum.

For a simple repro case, in a enum_test.py file paste this:

import proto

class BarEnum(proto.Message):
    class Bar(proto.Enum):
        BAR = 0
        BAZ = 1

class Foo(proto.Message):
    bars = proto.RepeatedField(
        proto.ENUM,
        number=1,
        enum=BarEnum.Bar
    )

Then from a repl:

>>> from enum_test import Foo, BarEnum
>>> foo = Foo()
>>> bar = BarEnum.Bar.BAR
>>> foo.bars.append(bar)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.pyenv/versions/3.7.0/lib/python3.7/_collections_abc.py", line 971, in append
    self.insert(len(self), value)
  File "~/lib/python3.7/site-packages/proto/marshal/collections/repeated.py", line 178, in insert
    pb_value = self._marshal.to_proto(self._pb_type, value, strict=True)
  File "~/lib/python3.7/site-packages/proto/marshal/marshal.py", line 215, in to_proto
    expected=proto_type.__name__, got=pb_value.__class__.__name__,
TypeError: Parameter must be instance of the same class; expected Bar, got int
@software-dov software-dov added the P1 An important bug label Mar 3, 2021
@software-dov software-dov self-assigned this Mar 3, 2021
@software-dov
Copy link
Contributor

Able to reproduce, working on a fix.

@software-dov
Copy link
Contributor

Turns out the nested enum isn't necessary to reproduce.

software-dov added a commit to software-dov/proto-plus-python that referenced this issue Mar 3, 2021
Fixes issue googleapis#201, where enums added to a repeated field triggered a
TypeError because they were coverted to integers during marshaling.
gcf-merge-on-green bot pushed a commit that referenced this issue Mar 4, 2021
Fixes issue #201, where enums added to a repeated field triggered a
TypeError because they were coverted to integers during marshaling.
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 An important bug triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants