DamienHarper/auditor-bundle

Call to a member function addEventSubscriber() on null in DoctrineProvider

hackzilla opened this issue · 10 comments

Q A
auditor-bundle version 5.2.4
PHP version 8.2.1
Database SQLite

Summary

When clearing caches on test env auditor gets null when retrieving the EventManager.
This issue appears to have been discussed in DamienHarper/auditor#141

Current behavior

Clearing the cache in test env throws an null on $entityManager->getEventManager() in DoctrineProvider

bin/console ca:cl  --env=test

 // Clearing the cache for the test environment with debug false                                                        

In DoctrineProvider.php line 51:
                                                          
  Call to a member function addEventSubscriber() on null
                                                          

cache:clear [--no-warmup] [--no-optional-warmers]

How to reproduce

The specific commit that is causing the issue is: 3f31c91

If I revert DHAuditorBundle compiler pass back to what it was before the commit, then it starts working again for us.

        $container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass());
//        $container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);

This is the case for 5.2.2 & 5.2.4
The issue did not occur in 5.2.1

Expected behavior

Caches should be cleared without error.

I've had a little dig and I can't see any reason and a blank project doesn't appear to cause this issue.
Even looked at the order of the complierPasses.

We aren't using auditable in test, and disabling it in test config didn't help.

dh_auditor:
    enabled: false

If it helps we have the following dependancies installed:

  • api-platform/core
  • aws/aws-sdk-php
  • doctrine/doctrine-bundle
  • doctrine/mongodb-odm-bundle
  • fresh/doctrine-enum-bundle
  • symfony 6.2
  • vich/uploader-bundle

I've had a little dig and I can't see any reason and a blank project doesn't appear to cause this issue. Even looked at the order of the complierPasses.

We aren't using auditable in test, and disabling it in test config didn't help.

dh_auditor:
    enabled: false

If it helps we have the following dependancies installed:

  • api-platform/core
  • aws/aws-sdk-php
  • doctrine/doctrine-bundle
  • doctrine/mongodb-odm-bundle
  • fresh/doctrine-enum-bundle
  • symfony 6.2
  • vich/uploader-bundle

I have the same bug, when running my tests KernelTestcase

@mkldevops We solved the issue by using composer patches.
Though it would be nice to get to the root cause of the issue.

diff --git a/src/DHAuditorBundle.php b/src/DHAuditorBundle.php
index 8221eb9..6aa12f9 100644
--- a/src/DHAuditorBundle.php
+++ b/src/DHAuditorBundle.php
@@ -21,7 +21,7 @@ class DHAuditorBundle extends Bundle
         parent::build($container);
 
         $container->addCompilerPass(new AddProviderCompilerPass());
-        $container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
+        $container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
         $container->addCompilerPass(new CustomConfigurationCompilerPass());
     }
 }

@hackzilla Doesn't work

I disabled the bundle on test environment

@mkldevops I couldn't figure out how to disable it, as it kept throwing the error.

Did you try @Marmelatze solution? @see DamienHarper/auditor#141 (comment)

Doesn't seem like a solution, but a workaround. Ghost objects and lazy loading are for performance (even on test env). Are there any plans to support ghost objects?

Did you try @Marmelatze solution?
@see DamienHarper/auditor#141 (comment)

@DamienHarper This worked for me.
I'll close this ticket, in favour of that ticket.

@DamienHarper Whilst it fixed cache clearing, it broke a bunch of stuff in out test suite.
For the moment, I'll go back to using my composer patch.