FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: to_dict returns wrong enum fields when numbering is not consecutive by boukeversteegh · Pull Request #102 · danielgtaylor/python-betterproto · GitHub

Fix: to_dict returns wrong enum fields when numbering is not consecutive - #102

Merged
boukeversteegh merged 3 commits into
danielgtaylor:masterfrom
boukeversteegh:fix/93_skipped_enum_values
Jul 12, 2020
Merged

Fix: to_dict returns wrong enum fields when numbering is not consecutive#102
boukeversteegh merged 3 commits into
danielgtaylor:masterfrom
boukeversteegh:fix/93_skipped_enum_values

Conversation

Copy link
Copy Markdown
Collaborator

closes #93

  • When converting to dictionary, get enum values by Enum() constructor, instead of index.
  • Small refactor: determine if a field is a list, not by its value, but by its type. (i.e. do not rely on the user to tell us what type our fields are).
  • Small refactor: removal of magic constants that were proto3 type names.
  • Added more tests for enum.

boukeversteegh added bug Something isn't working small Low effort issue that can easily be picked up labels Jul 4, 2020
boukeversteegh requested a review from nat-n July 8, 2020 21:10
Comment thread src/betterproto/__init__.py Outdated
Comment on lines +846 to +855
if field_is_repeated:
enum_class = field_type.__args__[0]
if isinstance(value, typing.Iterable):
output[cased_name] = [
enum_class(element).name for element in value
]
else:
warnings.warn(
f"Non-iterable value for repeated enum field {field_name}"
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The actual fix is here ☝️

boukeversteegh merged commit 6c29771 into danielgtaylor:master Jul 12, 2020
Gobot1234 pushed a commit to Gobot1234/python-betterproto that referenced this pull request Aug 24, 2020
…ive (danielgtaylor#102)

Fixes danielgtaylor#93 to_dict returns wrong enum fields when numbering is not consecutive
abn mentioned this pull request Nov 24, 2020

Copy link
Copy Markdown

Thanks for this bug fix! I just ran into this myself and it took me a while to realize the fix was available in version 2. Any when this will come out of beta?

Copy link
Copy Markdown
Collaborator

Thanks for this bug fix! I just ran into this myself and it took me a while to realize the fix was available in version 2. Any when this will come out of beta?

No but if you want this fix install betterproto==2.0.0b2

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working small Low effort issue that can easily be picked up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_dict returns wrong enum fields when numbering is not consecutive

4 participants


Back | FazBrowse Home | New Git URL