Skip to content

[BUG][PYTHON] should only allow timezone-aware datetime #19303

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

Open
4 of 5 tasks
robertschweizer opened this issue Aug 6, 2024 · 0 comments
Open
4 of 5 tasks

[BUG][PYTHON] should only allow timezone-aware datetime #19303

robertschweizer opened this issue Aug 6, 2024 · 0 comments

Comments

@robertschweizer
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • [] Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

As described in OAI/OpenAPI-Specification#1498 (comment), OpenAPI date-time strings must contain time-zone information.

In the Python client generator, the Pydantic fields are annotated with datetime, which allows timezone-naive objects to be passed. When serialized to strings, these do not contain time-zone information like a trailing Z or +00:00. This violates the OpenAPI spec.

openapi-generator version

7.7.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

I would change the type annotations for date-time format string to pydantic.types.AwareDatetime, to require the time-zone information that the OpenAPI spec asks for when objects are constructed in Python.

This can be a breaking change to users using lenient REST APIs with the generated client. It might also be annoying if server responses contain "incorrect" timezone-naive timestamps and client-side validation fails.

Looking forward to feedback on how this should be best handled, to correctly represent the OpenAPI spec but not be annoying to users.

@robertschweizer robertschweizer changed the title [BUG] Python client should only allow timezone-aware datetime [BUG][PYTHON] should only allow timezone-aware datetime Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant