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

Unable to parse oneof fields: Disabled token 'ONEOF' #152

Open
maciejlach opened this issue Apr 17, 2020 · 4 comments
Open

Unable to parse oneof fields: Disabled token 'ONEOF' #152

maciejlach opened this issue Apr 17, 2020 · 4 comments

Comments

@maciejlach
Copy link

When I try to compile following proto file:

syntax = "proto3";

message SampleMessage {
  oneof test_oneof {
     string name = 4;
     int64 value = 7;
  }
}

pyrobuf fails with following stack trace:

Traceback (most recent call last):
  File "C:\dev\.venv\Scripts\pyrobuf-script.py", line 11, in <module>
    load_entry_point('pyrobuf==0.9.3', 'console_scripts', 'pyrobuf')()
  File "c:\dev\.venv\lib\site-packages\pyrobuf\__main__.py", line 6, in main
    compiler.compile()
  File "c:\dev\.venv\lib\site-packages\pyrobuf\compile.py", line 88, in compile
    self._compile_spec()
  File "c:\dev\.venv\lib\site-packages\pyrobuf\compile.py", line 119, in _compile_spec
    self._generate(spec)
  File "c:\dev\.venv\lib\site-packages\pyrobuf\compile.py", line 133, in _generate
    msg_def = self.parser.parse_from_filename(filename, self.includes)
  File "c:\dev\.venv\lib\site-packages\pyrobuf\parse_proto.py", line 264, in parse_from_filename
    raise e
  File "c:\dev\.venv\lib\site-packages\pyrobuf\parse_proto.py", line 261, in parse_from_filename
    return cls(s).parse(fname=fname, includes=includes, disabled_tokens=disabled_tokens)
  File "c:\dev\.venv\lib\site-packages\pyrobuf\parse_proto.py", line 225, in parse
    imported['enums']
  File "c:\dev\.venv\lib\site-packages\pyrobuf\parse_proto.py", line 326, in _parse_message
    for token in tokens:
  File "c:\dev\.venv\lib\site-packages\pyrobuf\parse_proto.py", line 157, in tokenize
    token_type, line + 1, self.lines[line])
AssertionError: Disabled token 'ONEOF' found on line 4:   oneof test_oneof {

It looks like oneofs should supported as of 0.9.2 (#147).

@ahobsonsayers
Copy link

Make sure you are using the --proto3 flag. It should then work

@maciejlach
Copy link
Author

@ahobsonsayers Thank you, this works from the CLI.

Is it possible to include this as a parameter in setup.py?

@vmicode
Copy link

vmicode commented Apr 24, 2022

Make sure you are using the --proto3 flag. It should then work

@ahobsonsayers How ?
Could you show me an example ?
I have try --proto3=1 or --proto3=true, and return errors.

@haakonvt
Copy link

Just using --proto3 solved it for me

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

No branches or pull requests

4 participants