Zend Framework

Missing Dependency: Session_Resource with SaveHandler_DbTable dont bootstrap db resource

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.9.3
  • Component/s: Zend_Application
  • Labels:
    None

Description

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

Version is trunk 15883

  1. Session.diff
    23/Jul/09 3:14 PM
    2 kB
    Vladimir Michailenko
  2. Session.php
    23/Jul/09 3:14 PM
    3 kB
    Vladimir Michailenko

Issue Links

Activity

Hide
julien PAULI added a comment -

#ZF-6974 explains the problem with more details

Show
julien PAULI added a comment - #ZF-6974 explains the problem with more details
Hide
Vladimir Michailenko added a comment -

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

Show
Vladimir Michailenko added a comment - #ZF-6974 is marked as resolved, but this issue is still presenting in the trunk for me.
Hide
Adam Weinstock added a comment -

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.

Show
Adam Weinstock added a comment - 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.
Hide
Sebastian Krebs added a comment - - edited

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.

Show
Sebastian Krebs added a comment - - edited 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.
Hide
Adam Weinstock added a comment -

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.

Show
Adam Weinstock added a comment - 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.
Hide
Sebastian Krebs added a comment -

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.

Not the whole resource, but the Db-savehandler.

Show
Sebastian Krebs added a comment -
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.
Not the whole resource, but the Db-savehandler.
Hide
Adam Weinstock added a comment -

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.

Show
Adam Weinstock added a comment - 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.
Hide
Vladimir Michailenko added a comment -

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

Show
Vladimir Michailenko added a comment - Moved SaveHandler initialization from setOptions() to init() method (db should be initialized at this point).
Hide
Alexandre Nault added a comment -

This patch works for me!

Thank you for it.

Issue ZF-7168 resolved with the patch

Show
Alexandre Nault added a comment - This patch works for me! Thank you for it. Issue ZF-7168 resolved with the patch
Hide
Benjamin Eberlei added a comment - - edited

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

Show
Benjamin Eberlei added a comment - - edited Applied the patch and wrote a unittest suite for Session resource, merged into 1.9 release branch.

People

Vote (4)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: