#111271Extbase repositories used in backend module context return unpublished workspace records
Description
In a custom Extbase Backend module, repository queries return newly created, unpublished workspace records even when the Backend user is currently in the Live workspace. This happens even with a plain Repository::findAll() without any custom query settings or constraints. Interestingly, workspace overlays for existing records and their relations (including MM relations) work correctly. The issue appears to affect only records newly created in a workspace that have not yet been published.
Steps to reproduce
- Create an Extbase domain model with a workspace-enabled database table.
- Switch to a draft workspace and create a new record.
- Switch back to the Live workspace.
- Execute Repository::findAll() in a custom Extbase Backend module.
Expected behavior
Repository queries should respect the current Backend workspace:
- Live: Only published records are returned.
- Draft workspace: Published records (with workspace overlays applied) and newly created records belonging to the current workspace are returned.
Actual behavior
Newly created, unpublished workspace records are also returned in the Live workspace.
Current workaround
I currently add the following constraint to my Extbase repository queries:
public static function getWorkspaceConstraint(QueryInterface $query): ?ConstraintInterface
{
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
return $query->logicalOr(
// Already existing records (modified overlays are respected automatically by Extbase)
$query->equals('t3ver_wsid', 0),
// Newly created records (not in Live yet)
$query->logicalAnd(
$query->equals('t3ver_wsid', $GLOBALS['BE_USER']->workspace),
$query->in('t3ver_state', [-1, 1])
)
);
}
return null;
}
Applied to the repository query:
$query = $this->createQuery();
$query->matching(
self::getWorkspaceConstraint($query)
);
return $query->execute();
This produces the expected results in both Live and draft workspaces.
Possible cause
In Typo3DbQueryParser::getAdditionalWhereClause(), workspace records are filtered using t3ver_oid = 0. However, newly created workspace records also have t3ver_oid = 0 and are therefore not excluded. It seems that an additional restriction based on t3ver_wsid and the current Backend workspace is missing. Is this behavior intentional, or should Extbase repository queries automatically respect the current workspace?
Additional findings
I tested the existing core WorkspaceRestriction and confirmed that it resolves the issue when initialized with the current backend workspace id.
$queryParser = GeneralUtility::makeInstance(Typo3DbQueryParser::class);
$queryBuilder = $queryParser->convertQueryToDoctrineQueryBuilder($query);
$queryBuilder->getRestrictions()->add(new WorkspaceRestriction($GLOBALS['BE_USER']->workspace));
$dataMapper = GeneralUtility::makeInstance(DataMapper::class);
return $dataMapper->map(MyModel::class, $queryBuilder->executeQuery()->fetchAllAssociative());Reviews 3
History 17
-
Jan Kornblum changed description <span data-processor="relativetime" data-value="2026-10-28T15:38:24+00:00" > 10/28/26, 15:38 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 97241 status
NewUnder Review <span data-processor="relativetime" data-value="2026-10-30T15:05:00+00:00" > 10/30/26, 15:05 </span> -
Gerrit Code Review pushed patch set 2 for main to change 97241 <span data-processor="relativetime" data-value="2026-10-30T20:15:58+00:00" > 10/30/26, 20:15 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 97243 <span data-processor="relativetime" data-value="2026-10-30T21:13:53+00:00" > 10/30/26, 21:13 </span>
-
Gerrit Code Review pushed patch set 2 for 14.3 to change 97243 <span data-processor="relativetime" data-value="2026-10-30T21:28:05+00:00" > 10/30/26, 21:28 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 97313 <span data-processor="relativetime" data-value="2026-11-03T08:30:55+00:00" > 11/03/26, 08:30 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 97241 <span data-processor="relativetime" data-value="2026-11-03T09:48:30+00:00" > 11/03/26, 09:48 </span>