DamienHarper / auditor-bundle

The missing audit log library
MIT License
399 stars 121 forks source link

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

Closed hackzilla closed 1 year ago

hackzilla commented 1 year ago
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 https://github.com/DamienHarper/auditor/issues/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: https://github.com/DamienHarper/auditor-bundle/commit/3f31c91b9406ef5c2ffc005d15241f8798bce6ff

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.

hackzilla commented 1 year ago

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:

mkldevops commented 1 year ago

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

hackzilla commented 1 year ago

@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());
     }
 }
mkldevops commented 1 year ago

@hackzilla Doesn't work

mkldevops commented 1 year ago

I disabled the bundle on test environment

hackzilla commented 1 year ago

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

DamienHarper commented 1 year ago

Did you try @Marmelatze solution? @see https://github.com/DamienHarper/auditor/issues/141#issuecomment-1397949309

mvhirsch commented 1 year ago

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?

hackzilla commented 1 year ago

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.

hackzilla commented 1 year ago

@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.