#108995Anonymous Fe Session on Redis vs. DB
Description
anonymous fe sessions are handeled differently on redis vs. db backend. the following snippet works fine on \TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend::class (default), but failes if \TYPO3\CMS\Core\Session\Backend\RedisSessionBackend::class in $GLOBALS[‘TYPO3_CONF_VARS’][‘SYS’][‘session’][‘FE’][‘backend’] is used:
$userSessionManager = \TYPO3\CMS\Core\Session\UserSessionManager::create('FE');
$session = $userSessionManager->createFromRequestOrAnonymous(
$GLOBALS['TYPO3_REQUEST'],
'mysession',
);
$session->set('mykey', serialize(123));
$userSessionManager->updateSession($session);
this is because redis backend throws an error if no session is found (https://github.com/TYPO3/typo3/blob/13.4/typo3/sysext/core/Classes/Session/Backend/RedisSessionBackend.php#L190)
but db backend is okay with missing sessions (https://github.com/TYPO3/typo3/blob/13.4/typo3/sysext/core/Classes/Session/Backend/DatabaseSessionBackend.php#L169).
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] Anonymous Fe Session on Redis vs. DB Resolves: #108995 Releases: main
Files 1
History 4
-
Pascal Hofmair commented <span data-processor="relativetime" data-value="2026-02-17T09:54:03+00:00" > 02/17/26, 09:54 </span>
-
Markus Klein commented <span data-processor="relativetime" data-value="2026-02-17T15:00:07+00:00" > 02/17/26, 15:00 </span>
IMO the handling in the DB backend is wrong. Updating a non-existent session is a problem and should therefore throw the exception.
-
Sebastian Fischer commented <span data-processor="relativetime" data-value="2026-02-26T13:56:45+00:00" > 02/26/26, 13:56 </span>
@markus.klein I get your point, but what would be a work around? The AbstractUserAuthentication is not checking before setAndSaveSessionData https://github.com/TYPO3/typo3/blob/7e0de163ede35aa9e49adcbd82293b40be426142/typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php#L1060
Personal opinion: I don’t think that upsert ist a wrong pattern and redis is capable of upserts (update or insert) https://redis.io/docs/latest/commands/set/
-
Markus Klein commented <span data-processor="relativetime" data-value="2026-02-26T14:38:21+00:00" > 02/26/26, 14:38 </span>
@sfischer I have nothing against an “upsert” pattern, but then we should really rename the method as well. The name currently clearly suggests this is an update only!
Unfortunately not all DBMS we support actually have an “insert or update” semantic implemented. (MySQL?, SQlite?)So the options are to rename the method and implement “upsert” or throw the exception in the DatabaseBackend as well.
Regarding setAndSaveSessionData: The one you referenced is only used in BE context, where there is always a session present. => no problem.
The one for Frontend should handle this properly already. If it wouldn’t, we’d have massive complaints about missing session data in the bug tracker, I suppose.Hence, I opt to throw the exception and thereby ensuring to have consistent behavior in the SessionBackends and expected behavior for a method called “update”.
this causes an issue on sf_register registration plugin when captcha field is used: https://github.com/evoWeb/sf_register/issues/293