ZF-6942: Missing Dependency: Session_Resource with SaveHandler_DbTable dont bootstrap db resource

Issue Type: Bug Created: 2009-06-06T11:26:19.000+0000 Last Updated: 2009-09-17T15:44:49.000+0000 Status: Resolved Fix version(s): - 1.9.3 (22/Sep/09)

Reporter: Sebastian Krebs (kingcrunch) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Application

Related issues: - ZF-6974

Attachments: - Session.diff


Using Resource_Session with the DbTable-Savehandler cause an exception, if the Db-Resource is not called before.

Version is trunk 15883


Posted by julien PAULI (doctorrock83) on 2009-06-16T04:28:28.000+0000

ZF-6974 explains the problem with more details

Posted by Vladimir Michailenko (mich) on 2009-06-17T10:15:36.000+0000

ZF-6974 is marked as resolved, but this issue is still presenting in the trunk for me.

Posted by Adam Weinstock (adamweinstock) on 2009-07-14T00:46:06.000+0000

I'm getting this too.

The problem occurs because Zend_Application_Bootstrap_BootstrapAbstract::getPluginResourceNames() calls Zend_Application_Bootstrap_BootstrapAbstract::getPluginResources() which in turn calls Zend_Application_Bootstrap_BootstrapAbstract::_loadPluginResource(). This instantiates but does not execute instances of the registered resource objects, causing Zend_Application_Resource_Session::setSaveHandler() to instantiate an instance of Zend_Db_Table_Abstract before the Db resource is actually executed. Since Zend_Application_Resource_Db doesn't call Zend_Db_Table::setDefaultAdapter() until it's init() method is called, the desired behavior fails.

The simplest solution seems to be to remove the call to getPluginResources() in Zend_Application_Bootstrap_BootstrapAbstract::getPluginResourceNames(). This seems to be working for me, but may cause problems, so another solution may be more desirable. In any case, this bug will definitely cause problems with other resources down the line and should be fixed up.

Posted by Sebastian Krebs (kingcrunch) on 2009-07-14T01:09:02.000+0000

I think it should call bootstrap("db"), if the Db-Savehandler is used, because its a direct dependency and the manual mention, that dependencies should be solved this way. Maybe the savehandler-class call it itself, instead of the session-pluginresource.

Posted by Adam Weinstock (adamweinstock) on 2009-07-14T11:25:05.000+0000

I disagree Sebastian. Technically Zend_Application_Resource_Session is not dependent on Zend_Application_Resource_Db, so I don't think we should force this in the code.

If we wanted to focus the solution within the Zend_Application_Resource_Session class, we could think about restructuring things so the save handler instance, in this case an object of Zend_Db_Table_Abstract, isn't created until Zend_Application_Resource_Session::init() is called. In fact, I don't see why we can't move all of the logic in Zend_Application_Resource_Session::setSaveHandler() to Zend_Application_Resource_Session::init().

However, as I noted above, the problem we are encountering is tied to the way resources are setup, loaded, and executed, so it may be best to tackle the underlying logic to prevent future bugs with different resources.

Posted by Sebastian Krebs (kingcrunch) on 2009-07-14T11:32:31.000+0000

{quote}I disagree Sebastian. Technically Zend_Application_Resource_Session is not dependent on Zend_Application_Resource_Db, so I don't think we should force this in the code. {quote} Not the whole resource, but the Db-savehandler.

Posted by Adam Weinstock (adamweinstock) on 2009-07-14T11:48:08.000+0000

Yes, but Zend_Session_SaveHandler_DbTable isn't dependent on Zend_Application_Resource_Db either. It's a subclass of Zend_Db_Table_Abstract and must have an instance of Zend_Db_Adapter_Abstract set as it's adapter, but that adapter doesn't need to be created through an application resource.

Posted by Vladimir Michailenko (mich) on 2009-07-23T15:14:01.000+0000

Moved SaveHandler initialization from setOptions() to init() method (db should be initialized at this point).

Posted by Alexandre Nault (anault) on 2009-07-23T19:28:31.000+0000

This patch works for me!

Thank you for it.

Issue ZF-7168 resolved with the patch

Posted by Benjamin Eberlei (beberlei) on 2009-09-17T15:13:44.000+0000

Applied the patch and wrote a unittest suite for Session resource, merged into 1.9 release branch.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.