Skip to content

JSON request bodies serialize unknown types with str(), including datetime #1172

Open

Description

@vdusek

Every JSON body goes through json.dumps(..., default=str). There are three places: the generic path in HttpClientBase (_base.py#L326-L330), which push_items, Actor and task input and most other bodies use; the key-value store record encoder (encoding.py#L72-L79) used by set_record and Actor input; and the request queue batch encoder (request_queue.py#L82-L91).

Any value the json module cannot encode becomes its str():

json.dumps({'a': datetime(2026, 1, 1, tzinfo=UTC), 'b': {1, 2}, 'c': object()}, default=str)
# {"a": "2026-01-01 00:00:00+00:00", "b": "{1, 2}", "c": "<object object at 0x7f...>"}

A datetime is sent with a space instead of T, which is not ISO 8601 / RFC 3339 and which date parsers in Actors or downstream consumers may reject. A set, a dataclass or any custom object is stored as its repr in a dataset item or record. The call succeeds, and the bad value shows up only when someone reads the data.

The JS client calls JSON.stringify (base.ts#L781), so a Date goes out as ISO 8601 (2026-01-01T00:00:00.000Z) through its toJSON. setRecord rejects symbols, bigints, functions and non-finite numbers up front (key_value_store.ts#L58-L72), and when JSON.stringify fails (for example on a circular structure) it throws and tells the caller to pick another content type (key_value_store.ts#L566-L575).

Expected behavior

Use one shared default hook in all three places. It encodes datetime and date with isoformat() and raises TypeError for anything else, naming the type and suggesting to serialize the value first or, for set_record, to pass another content type. Keep allow_nan=False.

✍️ Drafted by Claude Code

Activity

  1. added this to the 4.0 milestone on Oct 30, 2026
  2. added
    bugSomething isn't working.
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Oct 30, 2026
  3. added theissue type on Oct 30, 2026
  4. removed
    bugSomething isn't working.
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    t-toolingIssues with this label are in the ownership of the tooling team.

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions