Skip to content
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

Add default string conversion for dates in JSON responses #4280

Merged
merged 2 commits into from
Aug 24, 2024

Conversation

DanielRyanSmith
Copy link
Collaborator

This change fixes a deployment bug that affected API responses.

TypeError: Object of type date is not JSON serializable

OpenAPI's to_dict() method will convert any value that is labeled with format: date to a date or datetime object, which is not JSON serializable by default. This can be solved more broadly by adding the default=str argument when converting to a JSON string, which denotes that any field that is not JSON serializable should be first type cast to a string.

Additionally, some of the items in the response are labeled as format: date, which drops any time granularity from the date. This is usually not needed, but I've converted timestamp-like fields to format: date-time. Other fields, like shipped_date, have been kept as date formats.

@DanielRyanSmith DanielRyanSmith merged commit e8f4661 into main Aug 24, 2024
7 checks passed
@DanielRyanSmith DanielRyanSmith deleted the 2024-08-23_gates-bugfix branch August 24, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants