Problem/Motivation
For translatable + revisionable content entities, core builds SQL joins that include a language condition when querying revision data.
In this path, the language column can be hard-coded as `langcode` for non-data-table joins, including the revision data table join.
This breaks entity types that define a custom langcode key (for example `language`) instead of the default `langcode`.
Result: SQL errors like “Unknown column ...field_revision.langcode in on clause” when opening translation/revision-related pages.
This is a correctness bug in SQL table alias/column resolution for entity query joins.
Steps to reproduce
1. Create a custom content entity type that is:
- translatable
- revisionable
- uses a custom langcode key (not named `langcode`)
2. Enable Content Translation for that entity type.
3. Create an entity and at least one revision.
4. Open the Translate page for that entity (or trigger a query that resolves latest translation-affected revision).
5. Observe SQL exception: unknown column `.langcode` in JOIN condition.
Proposed resolution
When selecting the language key for table joins, treat both data and revision data tables as entity-language-key tables.
Use the entity’s configured langcode key for:
- $entity_type->getDataTable()
- $entity_type->getRevisionDataTable()
Keep fallback behavior for other tables.
Example approach:
$data_tables = [$entity_type->getDataTable(), $entity_type->getRevisionDataTable()];
$langcode_key = in_array($table, $data_tables) ? $entity_type->getKey('langcode') : 'langcode';
This ensures joins target the actual language column defined by the entity type.
Remaining tasks
None.
User interface changes
None.
Introduced terminology
None.
API changes
No public API changes.
Internal query table/column resolution logic is corrected.
Data model changes
None.
No schema changes; only SQL generation logic is fixed.
Release notes snippet
Fixed an EntityQuery bug where revision-data table joins could hard-code `langcode`, causing SQL errors for translatable revisionable entities that use a custom langcode key. Translation/revision queries now correctly use the entity’s configured language key.
Issue fork drupal-3585716
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:
- 3585716-entityquery-uses-hard-coded
changes, plain diff MR !15501
Comments
Comment #2
lisotton commentedComment #4
lisotton commentedComment #5
smustgrave commentedThank you for reporting. Can we get a test case showing the problem as a next step please
Thanks
Comment #6
lisotton commentedComment #7
smustgrave commentedSince the tests run in isolation the try/finally shouldn't be needed.
Comment #8
lisotton commentedComment #9
smustgrave commentedRan a new pipeline to rerun tests for random failure (it was random)
Feedback appears to be addressed
Comment #10
godotislateThanks for the work on this. It's close, just had one minor nit. OK to self-RTBC once change is made.
I did think there must have been a more direct way to test that the query produces the expected result, but then I saw there are no revisionable entity types in core that use a custom langcode key. The only one I found that has a custom langcode key is
entity_test_mul_langcode_key, but that one's not revisionable. So short of creating a test entity type just for this purpose, I think the test is fine as is.Test only job fails as expected: https://git.drupalcode.org/issue/drupal-3585716/-/jobs/9586809
Comment #11
lisotton commented@godotislate I applied your suggestion in the MR, so I'm moving this back to RTBC.
Comment #16
godotislateCommitted and pushed 4504544 to main, 1b8823a to 11.x, and 2da39e6 to 11.4.x. Thanks!