#109912Exception in frontend when sys_redirect target is database record
Description
Bug #103937 seems to be back in version 14.
Creating custom linkhandler and redirecting to db record leads to Exception:
Call to a member function getId() on null
because there is no
$request->getAttribute('frontend.page.information')
in TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder
Steps to reproduce can be found in related issue #105648
Reviews 2
Related issues 3
History 1114
-
Christian Kuhn changed Related to #105648 <span data-processor="relativetime" data-value="2026-06-09T22:54:12+00:00" > 06/09/26, 22:54 </span>
-
Christian Kuhn changed Related to #103937 <span data-processor="relativetime" data-value="2026-06-09T22:54:19+00:00" > 06/09/26, 22:54 </span>
-
S P commented <span data-processor="relativetime" data-value="2026-06-17T06:30:30+00:00" > 06/17/26, 06:30 </span>
I confirm this. v14. Wanted to check whether #101156 is still relevant on v14, and got this exception.
Redirects and record links just don’t want to seem to play nicely together.
-
S P commented <span data-processor="relativetime" data-value="2026-06-17T07:04:10+00:00" > 06/17/26, 07:04 </span>
Did some analysis:
RedirectService->bootFrontendController()actually does create this request attribute before theDatabaseRecordLinkBuildergets called. This enrichedServerRequestis only passed into theContentObjectRenderer. TheDatabaseRecordLinkBuilderwhich will later be called seems to get the unaltered original request object.If I exchange, in
DatabaseRecordLinkBuilder$pageInformation = $request->getAttribute(‘frontend.page.information’);with
/** @var ContentObjectRenderer $cObj */
$cObj = $request->getAttribute(‘currentContentObject’);
$pageInformation = $cObj->getRequest()->getAttribute(‘frontend.page.information’);It works. The exception is then gone.
This comes at the very end from the fact that TYPO3’s
ServerRequestimplementation does aclonewhen setting attributes.public function withAttribute(string $name, $value): static
{
$clonedObject = clone $this;So, if you never pass this cloned object back then you have multiple versions of the request object floating around. Which is highly dangerous. Why does it clone itself? That does not make any sense. A request is basically a global singleton object. Even if it does not implement these architectural properties, it is from a semantical POV a global singleton, because you only ever get a single HTTP request to the whole application.
-
S P commented <span data-processor="relativetime" data-value="2026-06-17T07:13:18+00:00" > 06/17/26, 07:13 </span>
I just saw this in
ServerRequest->withAttribute(), which probably someone misunderstood:* This method MUST be implemented in such a way as to retain the * immutability of the message, and MUST return an instance that has the * updated attribute.This “immutability of the message” does not mean you have to
clonethe request object. This only means thatwithAttributemust not change anything else of the request object besides the one attribute in question. There’s no need for aclone. In fact cloning the request object can even cause a lot of harm and unneded assignments…From PSR:
> The various interfaces have been written with verbiage indicating that immutability MUST be preserved, but only indicate that “an instance” must be returned containing the new state. Since instances that represent the same value are considered equal, returning $this is functionally equivalent, and thus allowed.This certainly is true for
withAttributeand thus no cloning is ever needed when adding a new attribute to the request. -
Garvin Hicking commented <span data-processor="relativetime" data-value="2026-06-18T07:36:12+00:00" > 06/18/26, 07:36 </span>
The cloning here is actually needed because otherwise followup calls to a request object would make it mutable…
If you remove the `clone` in the class and execute the functional tests you will see a few scenarios that fail then:
1) TYPO3\CMS\Extbase\Tests\Functional\Mvc\Validation\ActionControllerValidationTest::argumentsOfOriginalRequestRemainOnValidationErrors Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( - 'blog' => [...] - 'blogPost' => [...] ) 9) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "flat keep_query_parameters" ('https://acme.com/flat-samehost-2', 'https://acme.com/', 200, null, null) Failed asserting that 404 matches expected 200. /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550 10) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "flat keep_query_parameters - with query parameters" ('https://acme.com/flat-samehos...f7dca0', 'https://acme.com/', 200, null, null) Failed asserting that 404 matches expected 200. /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550 11) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp" ('https://acme.com/regexp-samehost-1', 'https://acme.com/', 200, null, null) Failed asserting that 404 matches expected 200. /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550 12) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp keep_query_parameters" ('https://acme.com/regexp-samehost-2', 'https://acme.com/', 200, null, null) Failed asserting that 404 matches expected 200. /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550 13) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp keep_query_parameters - with query parameters" ('https://acme.com/regexp-sameh...e51f1a', 'https://acme.com/', 200, null, null) Failed asserting that 404 matches expected 200. /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550 14) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp respect_query_parameters" ('https://acme.com/regexp-samehost-3', 'https://acme.com/', 200, null, null) Failed asserting that 404 matches expected 200. /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550 15) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "same host as external target with fragment should pass instead of redirect" ('https://acme.com/sanatize-samehost-4', 'https://acme.com/', 200, null, null) Failed asserting that 404 matches expected 200. /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550 -
S P commented <span data-processor="relativetime" data-value="2026-06-18T07:48:04+00:00" > 06/18/26, 07:48 </span>
These are very likely different (but similar to this one here) architectural bugs at these places then, not inherently due the
clone(the clone just “hides” them).But yeah, it’s super unlikely that the
clonewill go (it’s not only TYPO3 who got this messed up, but basically every bigger project since PSR-7 back in 2015, everyone just copy-pasted this cloning-misbehaviour and got used to it).So, a realistic solution is to write back the cloned but attribute-enriched request object back to all places, not just passing it into the
ContentObjectRenderer. -
Gerrit Code Review pushed patch set 1 for main to change 95822 status
NewUnder Review <span data-processor="relativetime" data-value="2026-09-14T20:23:54+00:00" > 09/14/26, 20:23 </span> -
Gerrit Code Review pushed patch set 2 for main to change 95822 <span data-processor="relativetime" data-value="2026-10-02T09:38:54+00:00" > 10/02/26, 09:38 </span>
-
Georg Ringer changed Duplicated by #111080 <span data-processor="relativetime" data-value="2026-10-15T12:05:53+00:00" > 10/15/26, 12:05 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 96728 <span data-processor="relativetime" data-value="2026-10-15T15:48:18+00:00" > 10/15/26, 15:48 </span>
-
Georg Ringer commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-10-15T16:15:15+00:00" > 10/15/26, 16:15 </span>Applied in changeset commit:0a7bf7581517395dd7a4636a438c005709b2a6aa.
I can confirm this in TYPO3 14.3.2 with PHP 8.4 ad that the issue only appears for redirects with records as target.