Repository navigation
fix: encode datetime as ISO 8601 in JSON request bodies - #1203
Closed
RaphaelFakhri wants to merge 3 commits into
Closed
RaphaelFakhri wants to merge 3 commits into
RaphaelFakhri wants to merge 3 commits into
Conversation
JSON request bodies, JSON key-value store records and request queue batches were serialized with `json.dumps(..., default=str)`. A `datetime` went out as `2026-01-01 00:00:00+00:00`, with a space instead of `T`, and a `set` or any custom object was stored as its `str()` representation without an error. All three encoders now share one `default` hook. It encodes `datetime` and `date` with `isoformat()`, encodes pydantic URLs (left in place by Python-mode `model_dump()`, for example the webhook `request_url`) as strings, and raises `TypeError` for any other type. For `set_record()`, the error also suggests passing bytes or a string with a matching content type. Closes apify#1172
vdusek
requested changes
Nov 5, 2026
Contributor
|
Issue #1172 is in the 4.0 milestone because this change is breaking: calls that work on 3.4.0 would raise ✍️ Drafted by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
JSON request bodies and JSON key-value store records were serialized with
json.dumps(..., default=str). Adatetimewas sent as2026-01-01 00:00:00+00:00instead of ISO 8601, and asetor any custom object was stored as itsstr()representation without an error.This change adds one shared
defaulthook,json_defaultin_utils/http.py, and uses it in both encoders:datetime,dateandtimeare encoded withisoformat().UUIDis encoded withstr().AnyUrlobjects, for examplerequest_urlinWebhookClient.update(), which previously relied onstr().TypeErrorwith the type name. Forset_record(), the message also suggests passing bytes or a string with a matching content type.allow_nan=Falseis unchanged.model_dump(mode='json', fallback=str)first, so an unsupported value inuserDatais still sent as itsstr().The hook lives in
_utils/http.pybecause_utils/encoding.pyimportshttp_clients, so importing it fromhttp_clients/_base.pywould create a circular import.Issues
str(), includingdatetime#1172Testing
test_prepare_request_call_encodes_datetime_as_iso_8601test_prepare_request_call_encodes_time_and_uuid_as_stringstest_prepare_request_call_rejects_non_json_value(set,object)test_encode_key_value_store_record_value_encodes_datetime_as_iso_8601test_encode_key_value_store_record_value_rejects_non_json_valuetest_update_sends_request_url_as_string: guards the webhook URL path.ruff check,ruff format --check,ty check, andpoe check-docstringspass.