Add default string conversion for dates in JSON responses #4280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 withformat: date
to a date or datetime object, which is not JSON serializable by default. This can be solved more broadly by adding thedefault=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 toformat: date-time
. Other fields, like shipped_date, have been kept as date formats.