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 issue where numbering is messed up #57

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

prashantgupta24
Copy link
Member

@prashantgupta24 prashantgupta24 commented Aug 18, 2023

Try to fix #58

Getting the field number based on the len(field_descriptors) heavily relies on the fact that the fields are ordered.

In case he fields are annotated like this:

a: Str: 1
b: Union[x,y]: 3
c: 4
d: 2

then with the current logic, while determining the number for the 2 oneofs within b, one will get the number 2 len(field_descriptors) + oneof_field_idx and the other will get 3 len(field_descriptors) + oneof_field_idx (where len(field_descriptors) is an incorrect way of determining the number of fields that have already been handled).

Ideally, this can be just the field_number + oneof_field_idx, where we've already determined the field_number earlier?

Signed-off-by: Prashant Gupta <[email protected]>
Signed-off-by: Prashant Gupta <[email protected]>
Signed-off-by: Prashant Gupta <[email protected]>
Signed-off-by: Prashant Gupta <[email protected]>
class Foo:
bar: Annotated[bool, FieldNumber(1)]
foo: Union[bool, str]
baz: Annotated[bool, FieldNumber(2)]
Copy link
Member Author

Choose a reason for hiding this comment

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

This fails with

[Couldn't build proto file into descriptor pool: duplicate field number (2)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Computed field numbers are messed up if fields are not ordered
1 participant