#81208Invalid SQL query when previewing a workspace with translated relations
Description
DISCLAIMER
This is quite tricky and could not understand how to reproduce it in a vanilla install.
Context
- The problem happens for me when previewing a page from a workspace with a menu of categories associated to EXT:news records.
- In my case I have a custom extended domain model for news records but it does not seem to be related, I removed corresponding columns/fields from the query below
Preview crashes with:
An exception occurred while executing 'SELECT `uid_local`, `uid_foreign`, `tablenames`, `sorting`, `sorting_foreign`, `fieldname`, `uid`, `pid`, `tstamp`, `crdate`, `cruser_id`, `deleted`, `hidden`, `starttime`, `endtime`, `t3ver_oid`, `t3ver_id`, `t3ver_wsid`, `t3ver_label`, `t3ver_state`, `t3ver_stage`, `t3ver_count`, `t3ver_tstamp`, `t3ver_move_id`, `t3_origuid`, `sys_language_uid`, `l10n_parent`, `l10n_diffsource`, `title`, `description`, `parent`, `items`, `fe_group`, `images`, `single_pid`, `shortcut`, `import_id`, `import_source`, `seo_title`, `seo_description`, `seo_headline`, `seo_text`, `l10n_state` FROM `sys_category` WHERE (`pid` = ?) AND (`t3ver_oid` = ?) AND (`t3ver_wsid` = ?) AND (`sys_category`.`deleted` = 0) LIMIT 1' with params [-1, 29, 2]: Unknown column 'uid_local' in 'field list'
Call stack shows:
stacktrace.png
After quite some deep debugging, I could understand the context:
- This happens when the rows array which need to be overlaid in
\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend::doLanguageAndWorkspaceOverlay()are the result of a JOIN (in my case a JOIN fromsys_categoryandsys_category_record_mm - Each row is thus containing fields coming from both tables
- The test on
$sourceat the beginning of methoddoLanguageAndWorkspaceOverlayproperly detects that a JOIN is in use and extracts the right table (sys_category) - There are some tests whether the “original” record needs to be fetched, for instance when a move is detected, that’s not invoked in my case
- There is another test which detects that current record is a translation already and then would fetch the parent record instead, this is where the problem lies
- If current record is a default language record AND we are in the context of fetching the content of a workspace (method is invoked multiple times with same record causing no errors until the context of the call is the actual workspace preview), then it bypasses the action of reloading the record from database
- Since it bypasses this reload, call to
versionOLis made with a row containing additional columns fromsys_category_record_mmand since the test at the very beginning of methodversionOLsucceeds, there is a call to methodgetWorkspaceVersionOfRecordwith those invalid additional columns and this is the source of the SQL failure
Solution Found
The test to reload the original record is extended to check if we are in the context of a workspace preview and if so, ensure no additional columns are present
Reviews 5
- 10.4 66732[BUGFIX] Fetch original row from database when previewing a workspace
- main 52791[BUGFIX] Fetch original row from database when previewing a workspace
- 10.4 68935[BUGFIX] Resolve WS overlays in Extbase JOIN queries properly
- main 68915[BUGFIX] Resolve WS overlays in Extbase JOIN queries properly
- main 64333[BUGFIX] Fetch original row from database when previewing a workspace
Related issues 4
- Bug #82750Workspace preview doesn't preview MM relations properly
- Bug #85061Extbase doesn't overlay workspace records
- Bug #88784Record language is incorrectly changed to default language in overlayLanguageAndWorkspace
- Feature #90072Make inline TCA fields workspace-transparent for Extbase (foreign_field and foreign_sortby)