Reputation: 378
I use Propel to connect and query database and after upgrading from symfony 2.7 to symfony 2.8 I run into strange issue. When I completely remove content of cache directory and then run app/console
command I got this exception:
[PropelException] No connection information in your runtime configuration file for datasource [default]
This also happens everytime when I change configuration or translation files and then I refreshe page. When I do this once again it works fine though.
I figured out that this is caused by one of my service that is passed to twig as global variable like this in app/config/config.yml
:
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
settings: @app.settings
The service try to loads data from database in constructor:
<?php
namespace AppBundle\Services;
use AppBundle\Propel\SettingsQuery;
class PropelSettings {
private $settings = array();
public function __construct() {
$this->initialize();
}
public function initialize() {
$settings = SettingsQuery::create()
->select(array('key', 'value'))
->find();
foreach ( $settings as $s ) {
$this->settigns[$s['key']] = $s['value'];
}
}
public function get($key, $default = null) {
return isset($this->settings[$key]) ? $this->settings[$key] : $default;
}
}
but this happens before propel load configuration by calling boot() method in vendor/propel/propel-bundle/Propel/PropelBundle/PropelBundle.php
, which means that symfony try to create instance of service before it actually loads all bundles during warmup. This is not an issue in symfony 2.7 and erlier versions. This can be easily avoided by not querying database during construction of service, but is this correct behavior of symfony 2.8? Is there any way to force propel to be booted before symfony create any instance of service?
Upvotes: 3
Views: 569
Reputation: 530
Just try moving your initialization code out of the constructor (I know you already know that). Symfony does more during the cache warmup process than it did in 2.7. This service is instantiated likely due the Twig templates being warmed up. The probably issue is that Propel itself probably needs some cache to exist in order for it to be booted... or perhaps there's some code that helps boot Propel correctly during the request-response cycle.
In short: this looks like a quirk of Propel to me, but someone who knows more about Propel might know a way to forcefully "boot" it. Propel is special because of the static context it uses.
I hope that clarifies a little!
Upvotes: 2