Skip to content

Added function to 'lazyload' the repository - #580

Closed
winus wants to merge 3 commits into
FriendsOfSymfony:1.6from
winus:1.6
Closed

winus wants to merge 3 commits into
FriendsOfSymfony:1.6from
winus:1.6

Conversation

@winus

@winus winus commented May 17, 2018

Copy link
Copy Markdown

Yesterday while running automated test after merging our FOSOAuthServerBundle branch in our project we ran into a problem; unable to execute any command when there was no database available yet.
Our test environment script delete the database and creates is again with settings from the parameters.yml. ( plain doctrine command app/console doctrine:database:create etc.)

All commands would fail because the database would not exist. Even just a app/console.

After debugging narrowed it down to the ClientManager.php and the TokenManager.php which get a repositoryClass from doctrine. Doctrine tries to generate some meta data for the requested class.

Solution:
Moved the constructing of the repository from the constructor to a separate function. And altered some lines that used the property to use the function instead.

Stack trace:

[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'ris_testing'

Exception trace:
() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
PDO->__construct() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
Doctrine\DBAL\Driver\PDOConnection->__construct() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:44
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763
Doctrine\ORM\Mapping\ClassMetadataFactory->getTargetPlatform() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616
Doctrine\ORM\Mapping\ClassMetadataFactory->completeIdGeneratorMapping() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:281
Doctrine\ORM\EntityManager->getClassMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php:44
Doctrine\Bundle\DoctrineBundle\Repository\ContainerRepositoryFactory->getRepository() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:698
Doctrine\ORM\EntityManager->getRepository() at /Users/winus/Sites/vtr/app/cache/test/appTestDebugProjectContainer.php:5571
DoctrineORMEntityManager_000000002ee75b2c00000000050415f90305fe7feaaef79014396928be2670a6->getRepository() at /Users/winus/Sites/vtr/vendor/friendsofsymfony/oauth-server-bundle/Entity/ClientManager.php:40
FOS\OAuthServerBundle\Entity\ClientManager->__construct() at /Users/winus/Sites/vtr/app/cache/test/appTestDebugProjectContainer.php:1910
appTestDebugProjectContainer->getFosOauthServer_ClientManager_DefaultService() at /Users/winus/Sites/vtr/app/bootstrap.php.cache:2261
Symfony\Component\DependencyInjection\Container->get() at /Users/winus/Sites/vtr/app/cache/test/appTestDebugProjectContainer.php:1930
appTestDebugProjectContainer->getFosOauthServer_CreateClientCommandService() at /Users/winus/Sites/vtr/app/bootstrap.php.cache:2261
Symfony\Component\DependencyInjection\Container->get() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:147
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:112
Symfony\Bundle\FrameworkBundle\Console\Application->all() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:66
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
Symfony\Component\Console\Application->run() at /Users/winus/Sites/vtr/app/console:27

@winus

winus commented May 17, 2018

Copy link
Copy Markdown
Author

Altered the tests to pass. Don't know if this is enough.

@winus

winus commented May 17, 2018

Copy link
Copy Markdown
Author

#574 Seems to have about the same fix

Comment thread Entity/TokenManager.php
{
$this->repository = $this->em->getRepository($this->class);
}
return $this->repository;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a line break missing :)

Comment thread Entity/ClientManager.php
{
$this->repository = $this->em->getRepository($this->class);
}
return $this->repository;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@GuilhemN

Copy link
Copy Markdown
Member

Closing in favor of #574, thanks!

@GuilhemN GuilhemN closed this Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants