Git Product home page Git Product logo

Comments (4)

so1n avatar so1n commented on June 8, 2024 1

Thanks for the feedback, I will fix this in version 0.2.0.1.

from protobuf_to_pydantic.

calclavia avatar calclavia commented on June 8, 2024

@so1n There's another bug created that's caused by the fix.

For fields such as:

repeated string a = 1;

It now generates this:

a: typing.Optional[typing.List[str]] = Field(default_factory=list, default=None)

which is not allowed in Pydantic. You cannot have default_factory and a default.

from protobuf_to_pydantic.

so1n avatar so1n commented on June 8, 2024

@so1n There's another bug created that's caused by the fix.

For fields such as:

repeated string a = 1;

It now generates this:

a: typing.Optional[typing.List[str]] = Field(default_factory=list, default=None)

which is not allowed in Pydantic. You cannot have default_factory and a default.

Please provide the Protobuf file or Message, I can't reproduce the problem at the moment

from protobuf_to_pydantic.

calclavia avatar calclavia commented on June 8, 2024

@so1n Here it is:

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)

It doesn't happen if you only have a single repeated field b.

from protobuf_to_pydantic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.