Problem/Motivation

Individual and collection reads validate the language selector through one shared resolver: an unconfigured langCode is rejected with 422 and a detail naming the language.

The /related/ endpoint (GET .../{uuid}/{relationship-field}) reads the query parameter raw and never validates it, so the same typo gets a different and misleading answer depending on the relationship's cardinality:

  • a to-one relationship returns 404 ("The ... translation of the specified resource does not exist"), indistinguishable from a genuinely missing translation of a configured language;
  • a to-many relationship returns 200 with every target moved into meta.omitted, reported as a language miss.

Both answers tell the client the content is missing, when the truth is that the request named a language the site does not have. One contract, one error model: identical mistakes should produce identical status codes and details on every read surface.

Steps to reproduce

  1. Site with en (default) and fr configured, and an article with an entity-reference relationship.
  2. GET /jsonapi/node/article/{uuid}?langCode=es (unconfigured) → 422, "The specified language ("es") is invalid or has not been configured."
  3. GET /jsonapi/node/article/{uuid}/{to-one-relationship}?langCode=es → 404.
  4. GET /jsonapi/node/article/{uuid}/{to-many-relationship}?langCode=es → 200, with every target under meta.omitted.

Proposed resolution

Resolve the selector once at the top of getRelated() through the shared resolver (getResourceLanguage()) instead of reading the query parameter raw, and take the langcode from the resolved language. The resolver is memoized per request and already runs on the two sibling endpoints, so this adds no query and changes nothing for well-formed requests. Everything downstream keeps consuming the same value.

The error detail is not re-authored: the test references the same literal the individual endpoint's assertion uses, so the two strings cannot drift apart. Clients match on them.

Two notes on scope, because an earlier draft of this issue proposed more:

  • No header guards are added. Language request headers are deliberately inert on reads since #3613823, and Content-Language was retired as a write selector in #3614200. Routing through the shared resolver does not reintroduce a header rejection here: the resolver's Content-Language rejection is gated on the request not being cacheable, so it applies to writes only.
  • Genuinely missing translations of configured languages keep their current behavior: a to-one strict miss stays a 404 advertising the target's available translations, and to-many targets stay excluded and reported under meta.omitted.

A side effect worth having: the resolver throws a CacheableUnprocessableEntityHttpException carrying the config:configurable_language_list cache tag, so the related endpoint's rejection is now cacheable and self-invalidating when the language is later added, matching its sibling endpoints.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lauriii created an issue. See original summary.

  • lauriii committed c53ba6af on 1.0.x
    task: #3614384 /related/ reads do not validate langCode: an unconfigured...
lauriii’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.