Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-20541

Edge case where DB connection is not available

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 4.7.20
    • Fix Version/s: 4.7.23
    • Component/s: Core CiviCRM
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding
    • Verified?:
      No

      Description

      I have been hitting an edge case in a testing environment where it fails in the DAO because 

       

      $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]

      is null

       

      This happens during unit tests outside civi core tests and it's hard to see how it could happen outside tests. What happens is test 1 calls civicrm_initialize which populates $_DB_DATAOBJECT['CONNECTIONS'], however, on tearDown it is unpopulated.

       

      In test 2 it is NOT populated as civicrm_initialize returns early as the static variable is set to TRUE. Any function that instantiates a DAO, including calling CRM_Core_DAO::executeQuery will cause 'CONNECTIONS' to be populated. However, if the very first db action is an api create call then the 'BEGIN' mysql query will be the first one called. This bypasses executeQuery & uses an obscure alternative ->query() - which does NOT cause the connection to be populated. Because it is using a cached dao object it does not instantiate a new one, meaning that path is skipped too. I have simply done what executeQuery does and added a call to instantiate a DAO if connections does not exist

       

      Failed asserting that 'Trying to get property of non-objectArray
      (
      [trace] => #0 /Users/emcnaughton/buildkit/build/d46/civicrm/CRM/Core/DAO.php(347): PHPUnit_Util_ErrorHandler::handleError(8, 'Trying to get p...', '/Users/emcnaugh...', 347, Array)
      #1 /Users/emcnaughton/buildkit/build/d46/civicrm/Civi/Core/Transaction/Frame.php(132): CRM_Core_DAO->query('BEGIN')
      #2 /Users/emcnaughton/buildkit/build/d46/civicrm/Civi/Core/Transaction/Manager.php(87): Civi\Core\Transaction\Frame->begin()
      #3 /Users/emcnaughton/buildkit/build/d46/civicrm/CRM/Core/Transaction.php(125): Civi\Core\Transaction\Manager->inc(false)
      #4 /Users/emcnaughton/buildkit/build/d46/civicrm/Civi/API/Subscriber/TransactionSubscriber.php(139): CRM_Core_Transaction->__construct(false)
      #5 [internal function]: Civi\API\Subscriber\TransactionSubscriber->onApiPrepare(Object(Civi\API\Event\PrepareEvent), 'api.prepare', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
      #6 /Users/emcnaughton/buildkit/build/d46/civicrm/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call_user_func(Array, Object(Civi\API\Event\PrepareEvent), 'api.prepare', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
      #7 /Users/emcnaughton/buildkit/build/d46/civicrm/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'api.prepare', Object(Civi\API\Event\PrepareEvent))
      #8 /Users/emcnaughton/buildkit/build/d46/civicrm/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php(170): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('api.prepare', Object(Civi\API\Event\PrepareEvent))
      #9 /Users/emcnaughton/buildkit/build/d46/civicrm/Civi/API/Kernel.php(248): Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('api.prepare', Object(Civi\API\Event\PrepareEvent))
      #10 /Users/emcnaughton/buildkit/build/d46/civicrm/Civi/API/Kernel.php(160): Civi\API\Kernel->prepare(Object(Civi\API\Provider\MagicFunctionProvider), Array)
      #11 /Users/emcnaughton/buildkit/build/d46/civicrm/Civi/API/Kernel.php(92): Civi\API\Kernel->runRequest(Array)
      #12 /Users/emcnaughton/buildkit/build/d46/civicrm/api/api.php(43): Civi\API\Kernel->runSafe('Contact', 'create', Array)
      #13 /Users/emcnaughton/buildkit/build/d46/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php(83): civicrm_api3('Contact', 'create', Array)
      #14 /Users/emcnaughton/buildkit/build/d46/sites/all/modules/large_donation/tests/LargeDonationTest.php(30): BaseWmfDrupalPhpUnitTestCase->callAPISuccess('Contact', 'create', Array)
      #15 phar:///Users/emcnaughton/buildkit/bin/phpunit4/phpunit/Framework/TestCase.php(764): LargeDonationTest->setUp()
      #16 phar:///Users/emcnaughton/buildkit/bin/phpunit4/phpunit/Framework/TestResult.php(612): PHPUnit_Framework_TestCase->runBare()

        Attachments

          Activity

            People

            • Assignee:
              eileen Eileen McNaughton
              Reporter:
              eileen Eileen McNaughton
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: