Skip to content

[6769][IMP] endpoint_json2: let a method declare its own response fields - #31

Merged
yostashiro merged 1 commit into
19.0from
6769-imp-endpoint_json2-method-response-fields
Aug 9, 2026
Merged

[6769][IMP] endpoint_json2: let a method declare its own response fields#31
yostashiro merged 1 commit into
19.0from
6769-imp-endpoint_json2-method-response-fields

Conversation

@yostashiro

@yostashiro yostashiro commented Aug 9, 2026

Copy link
Copy Markdown
Member

QT6769

Lets an endpoint whose method is not read/search_read declare its response fields.

Problem

_check_json2_response_fields validated every response field against the target model's fields, for every endpoint. That is correct when the method is read or search_read, whose result rows are made of model fields. It is wrong for any other method: the keys are the method's own, and the model has no way to know them.

A method returning a derived value therefore could not name it at all — declaring it raised ValidationError, so the only way forward was to leave json2_response_fields empty. That turns off filtering and aliasing entirely and leaves the payload implicit in the Python, invisible to anyone reading the endpoint record.

Change

  • Plain names are validated only for the methods in FIELD_READING_METHODS (read, search_read). That is a policy list, not a taxonomy of the ORM and is not meant to grow: read_group also returns model field values and is deliberately excluded, since its rows carry keys of its own (__count, __domain) too. A module wanting its own method checked should constrain it where the payload is defined, which can pin the exact keys rather than merely "is a field of the model".
  • Dotted specs stay validated whatever the method is: _json2_resolve_dotted_fields resolves the base against Model._fields before fetching the related rows, so a base that is not a relational field can never resolve.
  • The constraint now also depends on json2_method, so switching an endpoint back to search_read re-runs the check instead of leaving behind keys the model does not have.

Nothing changes at execution time: filtering, aliasing and dotted resolution were already applied to the result of any method, not only search_read.

Notes

  • README.rst is not regenerated — the oca-gen-addon-readme hook is commented out in this repository's .pre-commit-config.yaml (line 57), so readme/CONFIGURE.md is updated but the generated file is left alone rather than hand-edited.
  • The same change is wanted upstream in [19.0][ADD] endpoint_json2 OCA/web-api#135, which is still open.
  • I could not execute the tests locally: addons_path is empty in this workspace's odoo.conf and a fresh database registered 667 modules with no endpoint* among them, so the namespace path did not include the repositories. Relying on CI here.

@yostashiro yostashiro changed the title [6769][IMP] endpoint_json2 [6769][IMP] endpoint_json2: let a method declare its own response fields Aug 9, 2026
@yostashiro
yostashiro force-pushed the 6769-imp-endpoint_json2-method-response-fields branch 5 times, most recently from 5a81da4 to 7c6aec3 Compare August 9, 2026 13:57
Response fields were validated against the target model's fields for every
endpoint. That is right when the method is read or search_read, whose result
rows are made of model fields, and wrong for any other method: its keys are its
own and the model has no way to know them. A method returning a derived value
therefore could not name it here at all, and had to leave the field empty --
which turns off filtering and aliasing entirely and leaves the payload implicit
in the code, invisible to anyone reading the endpoint record.

Plain names are now checked only for read and search_read. Dotted specs stay
checked whatever the method is, because _json2_resolve_dotted_fields resolves
their base against the model's fields before fetching the related rows, so a
base that is not a relational field can never resolve.

The constraint now also depends on the method, so that switching an endpoint
back to search_read re-runs the check rather than leaving keys behind that the
model does not have.

Assisted-by: Claude Opus 5
@yostashiro
yostashiro force-pushed the 6769-imp-endpoint_json2-method-response-fields branch from 7c6aec3 to b929701 Compare August 9, 2026 14:05
@yostashiro

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: b92970189d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yostashiro
yostashiro merged commit 047e5f1 into 19.0 Aug 9, 2026
2 checks passed
@yostashiro
yostashiro deleted the 6769-imp-endpoint_json2-method-response-fields branch August 9, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant