Skip to content

[18.0][FIX] endpoint: serialize payload values with Odoo's json_default - #163

Open
AungKoKoLin1997 wants to merge 1 commit into
OCA:18.0from
qrtl:18.0-fix-endpoint-json_default
Open

[18.0][FIX] endpoint: serialize payload values with Odoo's json_default#163
AungKoKoLin1997 wants to merge 1 commit into
OCA:18.0from
qrtl:18.0-fix-endpoint-json_default

Conversation

@AungKoKoLin1997

Copy link
Copy Markdown

Backport of #160 to 18.0.

_make_json_response called json.dumps() with no default= hook, so any payload value json cannot represent natively raised TypeError and the request returned a 500. Every other JSON response in Odoo goes through json.dumps(data, default=json_default) (odoo/http.py).

Pass the same hook here. It covers date, datetime, bytes, lazy and ReadonlyDict, and json.dumps applies it at every depth, so nested values are handled without walking the payload.

Also let an endpoint supply its own hook through the result dict, for exec modes that need to override how a type is rendered. json.dumps takes a single default= callable, so such a hook replaces Odoo's for the whole payload and is expected to delegate to json_default for the types it does not render itself.

Differences from the 19.0 PR:

  • The demo endpoint covering the case is added to demo/endpoint_demo.xml, since 18.0 still keeps the demo endpoints in demo data rather than in tests/common.py.
  • Domain does not exist in 18.0 (ir.rule._compute_domain returns a plain list), so the demo payload and the HTTP test only cover date/datetime.

Assisted-by: Claude Opus 5

@qrtl QT6815

_make_json_response called json.dumps() with no default= hook, so any
payload value json cannot represent natively raised TypeError and the
request returned a 500. Every other JSON response in Odoo goes through
json.dumps(data, default=json_default) (odoo/http.py).

Pass the same hook here. It covers date, datetime, bytes, lazy and
ReadonlyDict, and json.dumps applies it at every depth, so nested values
are handled without walking the payload.

Also let an endpoint supply its own hook through the result dict, for
exec modes that need to override how a type is rendered. json.dumps
takes a single default= callable, so such a hook replaces Odoo's for the
whole payload and is expected to delegate to json_default for the types
it does not render itself.

Backport of OCA#160.

Assisted-by: Claude Opus 5
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @simahawk,
some modules you are maintaining are being modified, check this out!

@AungKoKoLin1997
AungKoKoLin1997 marked this pull request as ready for review September 2, 2026 07:50

@yostashiro yostashiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants