Skip to content

Commit b6eeea0

Browse files
committed
Handle Unset Enums when deserializing
1 parent 8331aad commit b6eeea0

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_union_property.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
4646
try:
4747
a_property = UNSET
4848
_a_property = data
49-
if _a_property is not None:
49+
if _a_property is not None and _a_property is not UNSET:
5050
a_property = AnEnum(_a_property)
5151

5252
return a_property
5353
except: # noqa: E722
5454
pass
5555
a_property = UNSET
5656
_a_property = data
57-
if _a_property is not None:
57+
if _a_property is not None and _a_property is not UNSET:
5858
a_property = AnIntEnum(_a_property)
5959

6060
return a_property

end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
4646
try:
4747
a_property = UNSET
4848
_a_property = data
49-
if _a_property is not None:
49+
if _a_property is not None and _a_property is not UNSET:
5050
a_property = AnEnum(_a_property)
5151

5252
return a_property
5353
except: # noqa: E722
5454
pass
5555
a_property = UNSET
5656
_a_property = data
57-
if _a_property is not None:
57+
if _a_property is not None and _a_property is not UNSET:
5858
a_property = AnIntEnum(_a_property)
5959

6060
return a_property

openapi_python_client/templates/property_templates/enum_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% else %}
55
{{ property.python_name }} = {{ initial_value }}
66
_{{ property.python_name }} = {{ source }}
7-
if _{{ property.python_name }} is not None:
7+
if _{{ property.python_name }} is not None and _{{ property.python_name }} is not UNSET:
88
{{ property.python_name }} = {{ property.reference.class_name }}(_{{ property.python_name }})
99
{% endif %}
1010
{% endmacro %}

0 commit comments

Comments
 (0)