[6769][IMP] endpoint_json2: let a method declare its own response fields - #31
Merged
Merged
Conversation
yostashiro
force-pushed
the
6769-imp-endpoint_json2-method-response-fields
branch
5 times, most recently
from
August 9, 2026 13:57
5a81da4 to
7c6aec3
Compare
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
force-pushed
the
6769-imp-endpoint_json2-method-response-fields
branch
from
August 9, 2026 14:05
7c6aec3 to
b929701
Compare
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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.
QT6769
Lets an endpoint whose method is not
read/search_readdeclare its response fields.Problem
_check_json2_response_fieldsvalidated every response field against the target model's fields, for every endpoint. That is correct when the method isreadorsearch_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 leavejson2_response_fieldsempty. That turns off filtering and aliasing entirely and leaves the payload implicit in the Python, invisible to anyone reading the endpoint record.Change
FIELD_READING_METHODS(read,search_read). That is a policy list, not a taxonomy of the ORM and is not meant to grow:read_groupalso 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"._json2_resolve_dotted_fieldsresolves the base againstModel._fieldsbefore fetching the related rows, so a base that is not a relational field can never resolve.json2_method, so switching an endpoint back tosearch_readre-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.rstis not regenerated — theoca-gen-addon-readmehook is commented out in this repository's.pre-commit-config.yaml(line 57), soreadme/CONFIGURE.mdis updated but the generated file is left alone rather than hand-edited.addons_pathis empty in this workspace'sodoo.confand a fresh database registered 667 modules with noendpoint*among them, so the namespace path did not include the repositories. Relying on CI here.