#109716Cannot DI PageRepository in blank projects because constructor calls init which demands DB and other framework context
Description
As the title says:
If any class in a project based on v14 tries to inject TYPO3\CMS\Core\Domain\Repository\PageRepository in a constructor, DI composition fails at that class because TYPO3\CMS\Core\Domain\Repository\PageRepository calls it’s own “init()” function from the constructor and “init()” demands a configured DB.
The specific error is 1459422492 “The requested database connection named “Default” has not been configured.”
Caused because “init()” does a bunch of things that require configuration and context. The error above is simply the one that happens first and blocks the rest.
This makes it impossible to run `composer install` in a project that has not yet been configured with DB credentials as PageRepository instances cannot be created by DI.
Goes without saying, classes that can be required as constructor arguments in DI should not call any methods that require a fully configured framework to run.
Suggested fix is to initialize on-demand within class methods that require this extra context and avoid calling such methods in the constructor.
Discouraged fix is to prevent PageRepository from being used as DI constructor dependency (which is a valid use case).
Priority set to “must have” since DI of PageRepository is a completely valid use case which is prevented by this call-init-in-constructor approach.
Steps to reproduce:
- Create a blank project but don’t composer install it.
- In that project, require TYPO3v14.
- In that project, add at least one class which requires PageRepository as constructor argument and is registered for DI processing.
- Then run `composer install`
What happens:
- Install process breaks at script `assets:publish` with error above, resulting in a chicken/egg problem (can’t install without already being installed).
What is expected:
- Install process is able to finish without errors.
Reviews 5
- main 94222[TASK] Make PageRepository readonly
- 14.3 94218[BUGFIX] Avoid PageRepository->__construct()->init() DB call
- main 94210[BUGFIX] Avoid PageRepository->__construct()->init() DB call
- 14.3 93906[BUGFIX] Make asset:publish during `composer install` more resilient
- main 93878[BUGFIX] Make asset:publish during `composer install` more resilient
Related issues 3
History 1922
-
Garvin Hicking changed Related to #102819 <span data-processor="relativetime" data-value="2026-04-27T12:43:30+00:00" > 04/27/26, 12:43 </span>
-
Garvin Hicking commented and changed category <span data-processor="relativetime" data-value="2026-04-27T12:44:05+00:00" > 04/27/26, 12:44 </span>
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2026-04-27T12:46:27+00:00" > 04/27/26, 12:46 </span>
Ah ok, the bottom of your report specifically states the correlation to the “asset:publish” rework, which is moved more tightly into the TYPO3 scope and probably related to the System Resource API.
But still just to verify – this worked for you in v13 before, do I understand right?
-
Stefan Bürk commented <span data-processor="relativetime" data-value="2026-04-27T13:34:59+00:00" > 04/27/26, 13:34 </span>
Interessting. Using a extension (root package) for project setup works. Using a “raw” project and reuse the very same extension does not.
Here some commands to reproduce (or not in the first case):
works: extension used as project having such di on board
git clone git@github.com:sbuerk/sbuerk-tf-ext-demo-reactions.git \ && cd sbuerk-tf-ext-demo-reactions \ && git checkout bug-109716 \ && Build/Scripts/runTests.sh -t 14 -s composer -- require --no-update \ 'typo3/minimal':'^14' \ && Build/Scripts/runTests.sh -t 14 -s composer -- install -vvv \ && Build/Scripts/runTests.sh -t 14 -s composer -- exec typo3 -- setup -vvv \ --driver=sqlite \ --admin-username=john-doe \ --admin-user-password='John-Doe-1701D.' \ --admin-email='john.doe@example.com' \ --project-name='TYPO3 Contribution' \ --no-interaction \ --server-type=apache \ --force \ && Build/Scripts/runTests.sh -t 14 -s composer -- exec typo3 sites:state on \ && Build/Scripts/runTests.sh -t 14 -s composer -- exec typo3 \ && ls -la .Build/Web/_assets \ && ls -la .Build/Web/_assets_installnot-working: project scenario
mkdir -p verify-bug-109716 \ && cd verify-bug-109716 \ && composer init \ --name='demo/verify-bug-109716' \ --type='project' \ --no-interaction \ && mkdir -p packages \ && git clone git@github.com:sbuerk/sbuerk-tf-ext-demo-reactions.git packages/some-ext \ && composer repository add packages path "packages/*" \ && composer config minimum-stability "dev" \ && composer config prefer-stable true \ && composer config allow-plugins true \ && composer config sort-packages true \ && composer require --no-update \ "typo3/cms-backend":"~14.3.0@dev" \ "typo3/cms-core":"~14.3.0@dev" \ "typo3/cms-extbase":"~14.3.0@dev" \ "typo3/cms-fluid":"~14.3.0@dev" \ "typo3/cms-install":"~14.3.0@dev" \ "typo3/cms-setup":"~14.3.0@dev" \ "typo3/cms-belog":"~14.3.0@dev" \ "typo3/cms-dashboard":"~14.3.0@dev" \ "typo3/cms-extensionmanager":"~14.3.0@dev" \ "typo3/cms-filelist":"~14.3.0@dev" \ "typo3/cms-fluid-styled-content":"~14.3.0@dev" \ "typo3/cms-frontend":"~14.3.0@dev" \ "typo3/cms-info":"~14.3.0@dev" \ "typo3/cms-lowlevel":"~14.3.0@dev" \ "typo3/cms-rte-ckeditor":"~14.3.0@dev" \ "typo3/cms-styleguide":"~14.3.0@dev" \ "typo3/cms-tstemplate":"~14.3.0@dev" \ "typo3/cms-workspaces":"~14.3.0@dev" \ "sbuerk/tf-ext-demo-reactions":"@dev" \ && composer install -vvv \ && vendor/bin/typo3 typo3 -- setup -vvv \ --driver=sqlite \ --admin-username=john-doe \ --admin-user-password='John-Doe-1701D.' \ --admin-email='john.doe@example.com' \ --project-name='TYPO3 Contribution' \ --no-interaction \ --server-type=apache \ --force \ && vendor/bin/typo3 typo3 sites:state on \ && ls -la public/_assets \ && ls -la public/_assets_install -
Claus Due commented <span data-processor="relativetime" data-value="2026-04-27T13:44:02+00:00" > 04/27/26, 13:44 </span>
Garvin Hicking wrote in #note-3:
> Ah ok, the bottom of your report specifically states the correlation to the “asset:publish” rework, which is moved more tightly into the TYPO3 scope and probably related to the System Resource API.
>
> But still just to verify – this worked for you in v13 before, do I understand right?Correct – this worked in v13.
There’s a rather big comment in PageRepository which explains the problematic implementation: https://github.com/TYPO3/typo3/blob/13.4/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php#L170
It’s quite possible this error would also be raised on v13 and the difference is just that the class which DI’s the PageRepository loads on v14 but doesn’t load on v13 which is why I only see it on v14.
-
Helmut Hummel commented <span data-processor="relativetime" data-value="2026-04-27T16:11:42+00:00" > 04/27/26, 16:11 </span>
A stack trace would be extremely helpful I think.
Or if someone could answer why the class using the PageRepository is instantiated at all
so early. -
Helmut Hummel commented <span data-processor="relativetime" data-value="2026-04-27T16:32:21+00:00" > 04/27/26, 16:32 </span>
Stefan Bürk wrote in #note-4:
> composer init \
> —name=‘demo/verify-bug-109716’ \
> —type=‘project’ \
> —no-interaction \I cannot reproduce anything with this example. In fact, I can not find any PageRepository usages in sbuerk/sbuerk-tf-ext-demo-reactions
-
Helmut Hummel commented <span data-processor="relativetime" data-value="2026-04-27T16:33:33+00:00" > 04/27/26, 16:33 </span>
Helmut Hummel wrote in #note-6:
> A stack trace would be extremely helpful I think.
>
> Or if someone could answer why the class using the PageRepository is instantiated at all
> so early.Or a minimal setup with instruction of how to reproduce. Without that, I can only guess.
-
Helmut Hummel commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2026-04-27T17:54:23+00:00" > 04/27/26, 17:54 </span>Helmut Hummel wrote in #note-6:
> Or if someone could answer why the class using the PageRepository is instantiated at all
> so early.From my tests I observe the following:
- PageRepository can be injected in a Command class and there is no interference with other commands (list and asset:publish work like expected)
- calling the command when no DB connection is configured leads to the described exception
- calling the command when DB connection is configured is working
My conclusion:
- DI of PageRepository is working as expected (when TYPO3 DB is set up, it works, when not, it errors)
- DI of PageRepository must not be done in a class, that is instantiated in a calling path that is executed when TYPO3 is not yet set up
- AssetPublishCommand has no injections, that execute third party code. It however calls loadExtLocalconfDatabaseAndExtTables, which loads these files, which can trigger third party code that interferes. However, since quite a while DB operation are prohibited in that bootstrap state, so injecting PageRepository in a class that is instantiated during this process would violate this prohibition.
So from my current knowledge, there is nothing we can/ must change short term.
-
Claus Due commented <span data-processor="relativetime" data-value="2026-04-28T10:17:53+00:00" > 04/28/26, 10:17 </span>
IMHO it is a totally valid use case to have classes which has a DI dependency to PageRepository being instanced during boot time but is not calling any methods that require DB during boot time. So I disagree with Helmut’s statement that PageRepository DI must not be done in a class that is used during boot time.
Even if I did agree: It’s also a valid use case to instance such classes in listeners for the BootCompletedEvent, which fires as a consequence of code in `asset:publish`. This event sits after the boot state, which falls outside the “don’t instance such classes during boot time” argument.
But, you can also just read the comment I linked to in PageRepository which states full awareness that calling these methods in the constructor isn’t a good choice and should be done differently. Even acceptance tests in EXT:styleguide have to dance around this design choice. Sure, we can all just refactor to ad-hoc instancing with conditions to check if config exists, but that’s forcing us to write more bad design because the core contains self-admittedly bad design.
So I maintain that this should be fixed.
I quote the comment in PagRepository::init():
> This needs to vanish, the code must not be triggered by __construct().
-
Helmut Hummel commented <span data-processor="relativetime" data-value="2026-04-28T10:22:43+00:00" > 04/28/26, 10:22 </span>
Claus Due wrote in #note-10:
> So I maintain that this should be fixed.Can you please add exact steps to reproduce?
-
Helmut Hummel commented <span data-processor="relativetime" data-value="2026-04-28T10:39:09+00:00" > 04/28/26, 10:39 </span>
To clarify:
I agree, that PageRepository constructor needs to be fixed.
I fear though, that there won’t be an easy non breaking fix for v13 or v14 around the corner.
So maybe we can find something that fixes the most pressing issues on your end.Therefore and because this is the case in v13 as well, I want to understand, what changed for you in v14
that the issue becomes prevalent.Is it “only” that asset:publish is called during composer install?
Does your code fail in v13 as well (e.g. calling cli when DB is not configured)?Based on the answers to these questions, we can find appropriate workarounds or define todos on our end, that do not involve a major and potentially breaking refactoring of PageRepostitory.
Workarounds could be:
- TYPO3_SKIP_ASSET_PUBLISH=1 composer install
- declare the PageRepository injection as lazy
-
Claus Due commented <span data-processor="relativetime" data-value="2026-04-28T11:23:14+00:00" > 04/28/26, 11:23 </span>
Helmut Hummel wrote in #note-11:
> Claus Due wrote in #note-10:
> > So I maintain that this should be fixed.
>
> Can you please add exact steps to reproduce?I think the absolute fastest way to reproduce is to create and register an event listener for \TYPO3\CMS\Core\Core\Event\BootCompletedEvent and in the event handling function just add:
new PageRepository();(or declare PageRepository as constructor argument with DI enabled for the event listener class – anything that fires the constructor raises the error)
Then call composer install (within a project that has not configured DB yet).
Regarding your suggested workarounds, the only one that will work is lazy DI / ad-hoc instancing. The code I’m struggling with needs to be callable in contexts where I don’t personally control the ENV and can’t require third party users to specify asset publish skipping.
I just don’t think that’s a nice solution. And it’s a workaround I may have to repeat a multitude of times.
-
Helmut Hummel changed Related to #109728 <span data-processor="relativetime" data-value="2026-04-29T10:50:37+00:00" > 04/29/26, 10:50 </span>
-
Helmut Hummel commented <span data-processor="relativetime" data-value="2026-04-29T10:54:29+00:00" > 04/29/26, 10:54 </span>
@NamelessCoder Would this https://review.typo3.org/c/Packages/TYPO3.CMS/+/93878 fix the issue for you?
-
Helmut Hummel commented <span data-processor="relativetime" data-value="2026-05-18T16:47:27+00:00" > 05/18/26, 16:47 </span>
Helmut Hummel wrote in #note-15:
> @NamelessCoder Would this https://review.typo3.org/c/Packages/TYPO3.CMS/+/93878 fix the issue for you?@NamelessCoder Can you please check whether the change fixes the issue for you?
Thanks!
-
Helmut Hummel changed category priority
Must haveCould have target version TYPO3 Version1412 Complexityeasyhard <span data-processor="relativetime" data-value="2026-05-18T16:49:06+00:00" > 05/18/26, 16:49 </span> -
Gerrit Code Review pushed patch set 4 for main to change 94210 status
Needs FeedbackUnder Review <span data-processor="relativetime" data-value="2026-05-30T00:26:16+00:00" > 05/30/26, 00:26 </span> -
Gerrit Code Review pushed patch set 5 for main to change 94210 <span data-processor="relativetime" data-value="2026-05-30T00:30:15+00:00" > 05/30/26, 00:30 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 94218 <span data-processor="relativetime" data-value="2026-05-30T13:15:00+00:00" > 05/30/26, 13:15 </span>
-
Christian Kuhn commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-05-30T13:40:11+00:00" > 05/30/26, 13:40 </span>Applied in changeset commit:21ca571436bf7ce39446b45df8487a55514adf3b.
-
Christian Kuhn changed Related to #109925 <span data-processor="relativetime" data-value="2026-05-30T19:36:38+00:00" > 05/30/26, 19:36 </span>
This is also the case in v13 as far as I read the code, right? Because it feels like being specifically reported for v14?