8000 Compile fields in oneof as optional · AdrienVannson/python-betterproto@5e65d4f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e65d4f

Browse files
committed
Compile fields in oneof as optional
1 parent fd0bf4c commit 5e65d4f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/betterproto/plugin/models.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ def annotation(self) -> str:
569569

570570
@dataclass
571571
class OneOfFieldCompiler(FieldCompiler):
572+
@property
573+
def optional(self) -> bool:
574+
return True
575+
572576
@property
573577
def betterproto_field_args(self) -> List[str]:
574578
args = super().betterproto_field_args
@@ -579,13 +583,6 @@ def betterproto_field_args(self) -> List[str]:
579583

580584
@dataclass
581585
class PydanticOneOfFieldCompiler(OneOfFieldCompiler):
582-
@property
583-
def optional(self) -> bool:
584-
# Force the optional to be True. This will allow the pydantic dataclass
585-
# to validate the object correctly by allowing the field to be let empty.
586-
# We add a pydantic validator later to ensure exactly one field is defined.
587-
return True
588-
589586
@property
590587
def pydantic_imports(self) -> Set[str]:
591588
return {"model_validator"}

0 commit comments

Comments
 (0)
0