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

Crash when field has the same name as a system type #53

Closed
nyurik opened this issue May 22, 2020 · 3 comments
Closed

Crash when field has the same name as a system type #53

nyurik opened this issue May 22, 2020 · 3 comments
Labels
bug Something isn't working has test Has a (xfail) test that verifies the bugfix or feature medium priority small Low effort issue that can easily be picked up
Projects
Milestone

Comments

@nyurik
Copy link

nyurik commented May 22, 2020

This oneof definition generates valid Python code, but later it is not possible to parse or create an instance of TileValue because the name of the field is the same as the type. Should betterproto rename such fields automatically, or at least throw an error during the code generation? I spent considerable time trying to understand why this line was saying t is not a class:

elif issubclass(t, Enum):

message Tile {
        message Value {
                oneof val {
                        string string = 1;
                        float float = 2;
                        double double = 3;
                        int64 int = 4;
                        uint64 uint = 5;
                        sint64 sint = 6;
                        bool bool = 7;
                }
        }

        repeated Value values = 1;
}
@dataclass
class Tile(betterproto.Message):
    values: List["TileValue"] = betterproto.message_field(1)


@dataclass
class TileValue(betterproto.Message):
    string: str = betterproto.string_field(1, group="val")
    float: float = betterproto.float_field(2, group="val")
    double: float = betterproto.double_field(3, group="val")
    int: int = betterproto.int64_field(4, group="val")
    uint: int = betterproto.uint64_field(5, group="val")
    sint: int = betterproto.sint64_field(6, group="val")
    bool: bool = betterproto.bool_field(7, group="val")
@nat-n nat-n added the bug Something isn't working label May 23, 2020
@boukeversteegh boukeversteegh added this to Backlog in Betterproto May 25, 2020
@boukeversteegh
Copy link
Collaborator

Added testcase namespace_builtin_types

boukeversteegh added a commit to boukeversteegh/python-betterproto that referenced this issue May 25, 2020
@boukeversteegh boukeversteegh added has test Has a (xfail) test that verifies the bugfix or feature small Low effort issue that can easily be picked up labels May 25, 2020
@boukeversteegh boukeversteegh added this to the Better Fields milestone May 25, 2020
boukeversteegh added a commit to boukeversteegh/python-betterproto that referenced this issue May 26, 2020
@boukeversteegh
Copy link
Collaborator

This should have been fixed now for all types mentioned.
#70 documents the remaining unsupported names

Betterproto automation moved this from Backlog to Done Jul 12, 2020
@boukeversteegh
Copy link
Collaborator

Thank you for your report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has test Has a (xfail) test that verifies the bugfix or feature medium priority small Low effort issue that can easily be picked up
Projects
Betterproto
  
Done
Development

No branches or pull requests

3 participants