File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -1471,12 +1471,24 @@ def is_set(self, name: str) -> bool:
1471
1471
1472
1472
@classmethod
1473
1473
def _validate_field_groups (cls , values ):
1474
- meta = cls ._betterproto_meta .oneof_field_by_group # type: ignore
1474
+ group_to_one_ofs = cls ._betterproto_meta .oneof_field_by_group # type: ignore
1475
+ field_name_to_meta = cls ._betterproto_meta .meta_by_field_name # type: ignore
1476
+
1477
+ for group , field_set in group_to_one_ofs .items ():
1478
+
1479
+ if len (field_set ) == 1 :
1480
+ (field ,) = field_set
1481
+ field_name = field .name
1482
+ meta = field_name_to_meta [field_name ]
1483
+
1484
+ # This is a synthetic oneof; we should ignore it's presence and not consider it as a oneof.
1485
+ if meta .optional :
1486
+ continue
1475
1487
1476
- for group , field_set in meta .items ():
1477
1488
set_fields = [
1478
1489
field .name for field in field_set if values [field .name ] is not None
1479
1490
]
1491
+
1480
1492
if not set_fields :
1481
1493
raise ValueError (f"Group { group } has no value; all fields are None" )
1482
1494
elif len (set_fields ) > 1 :
Original file line number Diff line number Diff line change @@ -7,7 +7,11 @@ import {{ i }}
7
7
{% endfor %}
8
8
9
9
{% if output_file .pydantic_dataclasses %}
10
- from pydantic.dataclasses import dataclass
10
+ from typing import TYPE_CHECKING
11
+ if TYPE_CHECKING:
12
+ from dataclasses import dataclass
13
+ else:
14
+ from pydantic.dataclasses import dataclass
11
15
{% - else -%}
12
16
from dataclasses import dataclass
13
17
{% endif %}
You can’t perform that action at this time.
0 commit comments