Skip to content

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

Closed

Description

@forest-benchling

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

Activity

  1. forest-benchling commented on Apr 7, 2021

    @forest-benchling
    CollaboratorAuthor

    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

  2. dbanty commented on Apr 7, 2021

    @dbanty
    Collaborator

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

  3. forest-benchling commented on Apr 7, 2021

    @forest-benchling
    CollaboratorAuthor

    @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.

  4. added this to the Next milestone on May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions