Skip to content

Optional nullable model properties are deserialized from UNSET to None #381

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

Closed
forest-benchling opened this issue Apr 7, 2021 · 3 comments · Fixed by #420
Closed

Optional nullable model properties are deserialized from UNSET to None #381

forest-benchling opened this issue Apr 7, 2021 · 3 comments · Fixed by #420
Labels
🐞bug Something isn't working
Milestone

Comments

@forest-benchling
Copy link
Collaborator

forest-benchling commented Apr 7, 2021

Describe the bug
If a model has an optional nullable model property, then in the from_dict, if the key is not present in the dictionary, it is deserialized as None instead of UNSET.

This is also true for enum properties, and probably other types as well, but we haven't done an exhaustive search.

To Reproduce
This can already be seen in end_to_end_tests/golden-record/my_test_api_client/models/a_model.py:345, where the deserialized value is initialized to None.

Expected behavior
UNSET keys should be deserialized as UNSET.

OpenAPI Spec File
Existing openapi.json

Desktop (please complete the following information):

  • OS: [e.g. macOS 10.15.1]
  • Python Version: [e.g. 3.8.0]
  • openapi-python-client version [e.g. 0.1.0]

Additional context

@forest-benchling forest-benchling added the 🐞bug Something isn't working label Apr 7, 2021
@forest-benchling
Copy link
Collaborator Author

Sorry @dtkav for the barrage of feedback :) We are hoping to help out with some of it eventually, but don't have the bandwidth at the moment.

LMK if anything is unclear.

cc @dtkav @bowenwr @packyg

@dbanty
Copy link
Collaborator

dbanty commented Apr 7, 2021

@forest-benchling does this affect main, the released version, or both?

@forest-benchling
Copy link
Collaborator Author

@forest-benchling does this affect main, the released version, or both?

@dbanty Both. I think it has been around for a long time. It should be pretty easy to fix, though, it might just work to switch the order of checking optional/nullable in openapi_python_client/templates/property_templates/property_macros.py.jinja:6.

dbanty pushed a commit that referenced this issue May 12, 2021
… returned from the API [#420 & #381]. Thanks @forest-benchling!

* Handle optional nullable deserialization

* Fix test
@dbanty dbanty added this to the Next milestone May 12, 2021
p1-ra pushed a commit to P1sec/openapi-python-client that referenced this issue May 14, 2021
… returned from the API [openapi-generators#420 & openapi-generators#381]. Thanks @forest-benchling!

* Handle optional nullable deserialization

* Fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants