Generated with the help of an LLM.
Problem/Motivation
Filtering or sorting a JSON:API collection on a computed base field that has
no storage (for example Content Moderation's moderation_state)
produces two problems on current core:
- A PHP warning from the internal query access guard:
Warning: Undefined array key "moderation_state" in Drupal\jsonapi\Access\TemporaryQueryGuard->secureQuery() (line 140 of core/modules/jsonapi/src/Access/TemporaryQueryGuard.php)
- A 500 response:
QueryException: 'moderation_state' not found
(Tables::ensureEntityTable()), surfaced by jsonapi's
DefaultExceptionSubscriber.
Root cause for both: computed fields appear in
getFieldDefinitions() but not in
getFieldStorageDefinitions(), so they cannot be used in an entity
query. FieldResolver accepts them as valid filter/sort paths, then
the guard hits an undefined array key and the query builder throws.
The 500-vs-helpful-error aspect is already tracked in #3029213 (open since
2019). This issue is filed to capture the full current behavior on supported
core, including the TemporaryQueryGuard warning, which is new:
that class was added for the SA-CONTRIB-2026-113 fix and did not exist when
#3029213 was written. Filed as a single report for a complete repro; happy to
have it merged into #3029213 if maintainers prefer.
Steps to reproduce
- Install a site with the JSON:API and Content Moderation modules.
- Enable the Editorial workflow on a content type (e.g. Article).
- Request
/jsonapi/node/article?filter[moderation_state]=draft. - Observe the "Undefined array key" warning from
TemporaryQueryGuard::secureQuery(), followed by a 500.
Also reproduces with ?sort=moderation_state and any other
computed, storage-less field. Reproduced on 11.3.20.
Proposed resolution
- In
FieldResolver, detect filter/sort paths that resolve to a
computed (storage-less) field and respond with a
CacheableBadRequestHttpException(400) before the entity query is
built, instead of allowing a 500. This realizes what #3029213 asks for. - Guard
TemporaryQueryGuard::secureQuery()against specifiers
absent fromgetFieldStorageDefinitions()so it no longer emits the
PHP warning.
Remaining tasks
- Confirm scope with maintainers: proceed here, or fold into #3029213.
- Add test coverage (see #2916074): a computed-field filter/sort returns 400
and emits no PHP warning. - Implement and review.
User interface changes
None.
Introduced terminology
None.
API changes
Filtering or sorting a JSON:API resource on a computed field returns a
documented 400 Bad Request instead of a 500, and no longer emits a PHP
warning.
Data model changes
None.
Release notes snippet
Filtering or sorting a JSON:API collection on a computed field now returns a
400 Bad Request instead of a 500 error, and no longer emits an "Undefined array
key" PHP warning from the internal query access guard.
Comments
Comment #2
cilefen commented