Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3218

Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 2.5, 2.4.2, 2.4.4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux / Mint 15
      php 5.5.*

      Description

      Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in /home/greg/dev/product/insight/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1009 and defined

      Stack trace:

      [1] PHPUnit_Framework_Error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in /project/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1009 and defined
      at n/a
      in /project/vendor/doctrine/orm/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php line 47

      at PHPUnit_Util_ErrorHandler::handleError('4096', 'Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in /project/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1009 and defined', '/project/vendor/doctrine/orm/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php', '47', array('entity' => object(Violation), 'em' => object(EntityManager)))
      in /project/vendor/doctrine/orm/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php line 47

      at Doctrine\ORM\Event\PreUpdateEventArgs->__construct(object(Violation), object(EntityManager), null)
      in /project/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1009

      at Doctrine\ORM\UnitOfWork->executeUpdates(object(ClassMetadata))
      in /project/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 341

      at Doctrine\ORM\UnitOfWork->commit(null)
      in /project/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 389

      at Doctrine\ORM\EntityManager->flush()
      in /project/src/SensioLabs/Bundle/MyBundle/Controller/MyController.php line 127

      at SensioLabs\Bundle\MyBundle\Controller\MyController->ignoreAction(object(Request), object(Project), object(Analysis), '4')
      in line

      at call_user_func_array(array(object(MyController), 'ignoreAction'), array(object(Request), object(Project), object(Analysis), '4'))
      in /project/app/bootstrap.php.cache line 1043

      at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
      in /project/app/bootstrap.php.cache line 1015

      at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
      in /project/app/bootstrap.php.cache line 1154

      at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
      in /project/app/bootstrap.php.cache line 435

      at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
      in /project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Client.php line 81

      at Symfony\Component\HttpKernel\Client->doRequest(object(Request))
      in /project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php line 111

      at Symfony\Bundle\FrameworkBundle\Client->doRequest(object(Request))
      in /project/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php line 319

      at Symfony\Component\BrowserKit\Client->request('POST', '/projects/id-foo/analyses/2/rule/4/ignore', array('ignore_rule' => array('comment' => 'Message about why this rule has been ignored', '_token' => 'CxEFTSv4GZQSWYXtRt-eHybaML4z8I0WK1DHiwr8Ih0')))
      in /project/src/SensioLabs/Bundle/MyBundle/Test/Client.php line 489

      at SensioLabs\Bundle\MyBundle\Test\Client->ignoreRuleViolations('id-foo', '2', '4', false)
      in /project/src/SensioLabs/Bundle/MyBundle/Tests/Acceptance/ViolationCommentsTest.php line 217

      at SensioLabs\Bundle\MyBundle\Tests\Acceptance\ViolationCommentsTest->testDashboardWithCriticalIgnoredRules()
      in line

      at ReflectionMethod->invokeArgs(object(ViolationCommentsTest), array())
      in /project/vendor/phpunit/phpunit/src/Framework/TestCase.php line 951

      at PHPUnit_Framework_TestCase->runTest()
      in /project/vendor/phpunit/phpunit/src/Framework/TestCase.php line 817

      at PHPUnit_Framework_TestCase->runBare()
      in /project/vendor/phpunit/phpunit/src/Framework/TestResult.php line 686

      at PHPUnit_Framework_TestResult->run(object(ViolationCommentsTest))
      in /project/vendor/phpunit/phpunit/src/Framework/TestCase.php line 753

      at PHPUnit_Framework_TestCase->run(object(PHPUnit_Framework_TestResult))
      in /project/vendor/phpunit/phpunit/src/Framework/TestSuite.php line 675

      at PHPUnit_Framework_TestSuite->run(object(PHPUnit_Framework_TestResult))
      in /project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php line 426

      at PHPUnit_TextUI_TestRunner->doRun(object(PHPUnit_Framework_TestSuite), array('listGroups' => false, 'loader' => null, 'useDefaultConfiguration' => true, 'configuration' => '/project/app/phpunit.xml.dist', 'filter' => 'testDashboardWithCriticalIgnoredRules', 'testSuffixes' => array('Test.php', '.phpt')))
      in /opt/dotfiles/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php line 176

      at PHPUnit_TextUI_Command->run(array('/usr/local/bin/phpunit', 'c', 'app/', '-filter', 'testDashboardWithCriticalIgnoredRules', 'src/SensioLabs/Bundle/MyBundle/Tests/Acceptance/ViolationCommentsTest.php'), true)
      in /opt/dotfiles/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php line 129

      at PHPUnit_TextUI_Command::main()
      in /opt/dotfiles/vendor/phpunit/phpunit/composer/bin/phpunit line 63

      I fails in this code

          private function executeUpdates($class)
          {
              $className          = $class->name;
              $persister          = $this->getEntityPersister($className);
              $preUpdateInvoke    = $this->listenersInvoker->getSubscribedSystems($class, Events::preUpdate);
              $postUpdateInvoke   = $this->listenersInvoker->getSubscribedSystems($class, Events::postUpdate);
      
              foreach ($this->entityUpdates as $oid => $entity) {
                  if ($this->em->getClassMetadata(get_class($entity))->name !== $className) {
                      continue;
                  }
      
                  if ($preUpdateInvoke != ListenersInvoker::INVOKE_NONE) {
      // => this line
                      $this->listenersInvoker->invoke($class, Events::preUpdate, $entity, new PreUpdateEventArgs($entity, $this->em, $this->entityChangeSets[$oid]), $preUpdateInvoke);
                      $this->recomputeSingleEntityChangeSet($class, $entity);
                  }
      
                  if ( ! empty($this->entityChangeSets[$oid])) {
                      $persister->update($entity);
                  }
      
                  unset($this->entityUpdates[$oid]);
      
                  if ($postUpdateInvoke != ListenersInvoker::INVOKE_NONE) {
                      $this->listenersInvoker->invoke($class, Events::postUpdate, $entity, new LifecycleEventArgs($entity, $this->em), $postUpdateInvoke);
                  }
              }
          }
      

        Activity

        Hide
        Marco Pivetta added a comment -

        Flushing in a listener that acts during EntityManagerInterface#flush() is disallowed.

        Show
        Marco Pivetta added a comment - Flushing in a listener that acts during EntityManagerInterface#flush() is disallowed.
        Hide
        Marco Pivetta added a comment -

        I'm marking this issue as incomplete: not reproducible without a test case.

        Show
        Marco Pivetta added a comment - I'm marking this issue as incomplete: not reproducible without a test case.
        Hide
        Grzegorz Korba added a comment -

        I'm facing this problem right now (doctrine/orm 2.5).

        In my case:

        • We have listener for one specified entity's field, which subscribes to preUpdate, postPersist and postUpdate
        • in preUpdate we check if this is valid entity and old value of specified field differs from new value, if yes we internally store some array with data like below:
          [
          'mode' => 'manual',
          'entity' => $entity,
          'oldValue' => $oldValue,
          'newValue' => $newValue,
          ]
          
        • in postPersist (works ok) and postUpdate (ContextErrorException) we're using custom logger, which has handler based on database, for storing changelog record. We create new entity, which has relation to modified entity. Exception rises when flushing changelog entity, which again dispatches preUpdate on related entity with null 3rd argument.

        I can't post more code because it's company's property, but flow is described and clear (I think so).

        Show
        Grzegorz Korba added a comment - I'm facing this problem right now (doctrine/orm 2.5). In my case: We have listener for one specified entity's field, which subscribes to preUpdate , postPersist and postUpdate in preUpdate we check if this is valid entity and old value of specified field differs from new value, if yes we internally store some array with data like below: [ 'mode' => 'manual', 'entity' => $entity, 'oldValue' => $oldValue, 'newValue' => $newValue, ] in postPersist (works ok) and postUpdate ( ContextErrorException ) we're using custom logger, which has handler based on database, for storing changelog record. We create new entity, which has relation to modified entity. Exception rises when flushing changelog entity, which again dispatches preUpdate on related entity with null 3rd argument. I can't post more code because it's company's property, but flow is described and clear (I think so).
        Hide
        Marco Pivetta added a comment -

        That's not enough to reproduce the problem. From what I am thinking, this looks like a case where flush() was called (again) in a listener (unsupported).

        I suggest you to write a test case, if this is still valid.

        Show
        Marco Pivetta added a comment - That's not enough to reproduce the problem. From what I am thinking, this looks like a case where flush() was called (again) in a listener (unsupported). I suggest you to write a test case, if this is still valid.
        Hide
        Grzegorz Korba added a comment -

        Yes, flush() was called in postUpdate.. I've changed it to connection's insert() and now it works. Too bad it's unsupported (and not intuitive).

        Show
        Grzegorz Korba added a comment - Yes, flush() was called in postUpdate .. I've changed it to connection's insert() and now it works. Too bad it's unsupported (and not intuitive).

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Grégoire Pineau
          • Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: