Skip to content

Conversation

@mhsdesign
Copy link
Member

For every simple GET request persistAllowedObjects is called via the Package.php in flow. This results in building a db connection, even if there is nothing to do.

We first check if the entityManager is open and if the entity manager has not been used (something is heavily cached via middle-ware or sth) flows objectmanagement retrieves the entity manger.

Now in this retrieval process - even though doctrines connection is lazy itself - the connection will be made forcefully see \Neos\Flow\Persistence\Doctrine\EntityManagerFactory::create line 120 (

) or
$entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping($typeConfiguration['dbType'], $typeName);

This is ironic because if there is no connection - or no entity manager in the first place, the current process cannot have made any changes to the transaction.

Upgrade instructions

Review instructions

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

@kitsunet
Copy link
Member

Please have a look at the Flow Package.php, which runs the persistAll after controller. There is a condition in there on:

$bootstrap->getObjectManager()->has(Persistence\PersistenceManagerInterface::class)

this is wrong though, not sure if that has ever changed in the object manager or if the condition was wrong since ever, but flipping that to:

$bootstrap->getObjectManager()->hasInstance(Persistence\PersistenceManagerInterface::class)

Should fix this as well?!

@kdambekalns kdambekalns changed the title BUGFIX: Prevent premature connection to database in PersistenceManagr::persistAllowedObjects BUGFIX: Prevent premature connection to database in PersistenceManager::persistAllowedObjects Jul 16, 2025
@kdambekalns
Copy link
Member

Please have a look at the Flow Package.php, which runs the persistAll after controller. There is a condition in there on:

Good catch!

$bootstrap->getObjectManager()->has(Persistence\PersistenceManagerInterface::class)

this is wrong though, not sure if that has ever changed in the object manager

The has() was added with #1163 by @kitsunet 😎

or if the condition was wrong since ever, but flipping that to:

$bootstrap->getObjectManager()->hasInstance(Persistence\PersistenceManagerInterface::class)

That was changed from hasinstance() to has() in #1366 (a PR by @kitsunet) – but in this case it was @kdambekalns who made that particular commit in that PR. 🙈

Whatever made me think hasInstance() is deprecated and has() was the replacement… 🤷‍♂️

@kitsunet
Copy link
Member

kitsunet commented Jul 16, 2025

Thanks for looking that up.

I actually expected it was myself breaking my own code from before 😂. has is part of the Psr ContainerInterface so that might have looked sensible in the "change to PSR" methods change. Sadly there is no ContainerInterface replacement for hasInstance

…anager::persistAllowedObjects`

For every simple GET request `persistAllowedObjects` is called via the Package.php in flow.
This results in building a db connection, even if there is nothing to do.

So if neither the persistentManger nor the entityManager has been created by the object manager instantiating one and thus the other which leads to "work".

For the check if the `entityManager` `isOpen` we activate the lazy dependency.

Now in this retrieval process - even though doctrines connection is lazy itself - the connection will be made forcefully
see `\Neos\Flow\Persistence\Doctrine\EntityManagerFactory::create` line 120 (https://github.com/neos/flow-development-collection/blob/11e2348125dd8286ff9ccc088e5d187dc9143bf5/Neos.Flow/Classes/Persistence/Doctrine/EntityManagerFactory.php#L120) or https://github.com/neos/flow-development-collection/blob/d93b6b09ca2071c87812a9ef4bc120201c44608a/Neos.Flow/Classes/Persistence/Doctrine/EntityManagerConfiguration.php#L229

This is ironic because if there is no connection - or no entity manager and persistence manager in the first place, the current process cannot have made any changes to the transaction.

Reason for this is that the Package.php has a wrong check which looks for if the PersistenceManager _exists_ as php class at all rather than if we have an active instance loaded.
This is an old regression from: neos@163e204
@mhsdesign mhsdesign force-pushed the bugfix/prevent-premature-connection-to-database branch from 70d0e90 to b2c163c Compare July 23, 2025 15:12
@mhsdesign
Copy link
Member Author

Should fix this as well?!

indeed. Good catch thank you both for digging into that as well.

Adjusted that and tested it:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants