Skip to content

Optional date-time attribute with value None gets isoparse'd #671

Closed
@ololobus

Description

@ololobus

Describe the bug
I have a similar problem to #456, but in my case date-time attribute isn't marked as required. Yet, the model's from_dict method has following code:

_retry_at = d.pop("retry_at", UNSET)
retry_at: Union[Unset, datetime.datetime]
if isinstance(_retry_at, Unset):
    retry_at = UNSET
else:
    retry_at = isoparse(_retry_at)

which tries to parse None value if there is no retry_at in the server response.

To Reproduce
Client is generated like this

poetry run openapi-python-client generate --path ../swagger/$(API_VERSION)/swagger.json

Expected behavior
Client doesn't try to parse absent date-time attributes in the response.

OpenAPI Spec File

{
    "openapi": "3.0.0",
    "servers": [
        {
            "url": "/api/v1"
        }
    ],
    "components": {
        "schemas": {
            "Operation": {
                "type": "object",
                "required": [
                    "id"
                ],
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "retry_at": {
                        "type": "string",
                        "format": "date-time"
                    }
                }
            }
        }
    }
}

Desktop (please complete the following information):

  • OS: Linux, PopOS 22
  • Python Version: 3.9.0
  • openapi-python-client version: 0.11.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions