Skip to content

[19.0][FIX] endpoint: serialize payload values with Odoo's json_default - #160

Merged
OCA-git-bot merged 1 commit into
OCA:19.0from
qrtl:19.0-fix-endpoint-json_default
Sep 1, 2026
Merged

[19.0][FIX] endpoint: serialize payload values with Odoo's json_default#160
OCA-git-bot merged 1 commit into
OCA:19.0from
qrtl:19.0-fix-endpoint-json_default

Conversation

@yostashiro

Copy link
Copy Markdown
Member

_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, Domain, 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.

Assisted-by: Claude Opus 5

@qrtl QT6815

@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

_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, Domain, 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.

Assisted-by: Claude Opus 5
@yostashiro
yostashiro force-pushed the 19.0-fix-endpoint-json_default branch from bf660ed to b1428cb Compare August 30, 2026 06:59

@AungKoKoLin1997 AungKoKoLin1997 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@simahawk simahawk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!
Could you backport it to v18 pls?

@simahawk

simahawk commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 19.0-ocabot-merge-pr-160-by-simahawk-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 4c8481b into OCA:19.0 Sep 1, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at dcd1972. Thanks a lot for contributing to OCA. ❤️

@yostashiro

Copy link
Copy Markdown
Member Author

LGTM, thanks! Could you backport it to v18 pls?

@AungKoKoLin1997 Can you please help take care of this.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants