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

default_factory and default generated together #24

Closed
calclavia opened this issue Oct 2, 2023 · 0 comments · Fixed by #25
Closed

default_factory and default generated together #24

calclavia opened this issue Oct 2, 2023 · 0 comments · Fixed by #25

Comments

@calclavia
Copy link

calclavia commented Oct 2, 2023

Describe the bug
Follow up on #22

For certain protobufs, this plugin generates a default and a default_factory in Pydantic which causes an error.

To Reproduce
Steps to reproduce the behavior:

syntax = "proto3";

message A {
    optional string a = 2;
    repeated string b = 3;
}

Output:

# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.1](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.3
# Pydantic Version: 1.10.12
from google.protobuf.message import Message  # type: ignore
from pydantic import BaseModel
from pydantic import Field
import typing


class A(BaseModel):
    a: typing.Optional[str] = Field(default="")
    b: typing.Optional[typing.List[str]] = Field(default_factory=list, default=None)

Expected behavior
It should only generate the default factory list for repeated and not default=None.

so1n added a commit that referenced this issue Oct 6, 2023
@so1n so1n linked a pull request Oct 6, 2023 that will close this issue
@so1n so1n closed this as completed in #25 Oct 6, 2023
so1n added a commit that referenced this issue Oct 6, 2023
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 a pull request may close this issue.

1 participant