Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine argument type error #134

Closed
kgrycuk opened this issue Aug 31, 2020 · 11 comments
Closed

Doctrine argument type error #134

kgrycuk opened this issue Aug 31, 2020 · 11 comments

Comments

@kgrycuk
Copy link

kgrycuk commented Aug 31, 2020

I used this bundle in a similar project a couple months ago without issue, but now I have several type errors with Doctrine related classes and functions.

Here is an example of an error after running a php bin/console on fresh symfony project.

In DoctrineRunManager.php line 18:
Argument 1 passed to Dtc\QueueBundle\Doctrine\DoctrineRunManager::__construct() must be an instance of 
Doctrine\Common\Persistence\ObjectManager, instance of Doctrine\ORM\EntityManager given, called in 
var/cache/dev/ContainerRCamxjS/getDtcQueue_Manager_Run_OrmService.php on line 25

Steps to recreate:

  1. Create new symfony project symfony new project-name --full
  2. Allow contrib as per Dtc documentation composer config extra.symfony.allow-contrib true
  3. Require dtc bundle composer require mmucklo/queue-bundle
  4. Run a php bin/console and you should get an error

Here is what my composer.json looks like

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": ">=7.2.5",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "composer/package-versions-deprecated": "^1.11",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^2.1",
        "doctrine/doctrine-migrations-bundle": "^3.0",
        "doctrine/orm": "^2.7",
        "mmucklo/queue-bundle": "^6.2",
        "phpdocumentor/reflection-docblock": "^5.2",
        "sensio/framework-extra-bundle": "^5.1",
        "symfony/asset": "5.1.*",
        "symfony/console": "5.1.*",
        "symfony/dotenv": "5.1.*",
        "symfony/expression-language": "5.1.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "5.1.*",
        "symfony/framework-bundle": "5.1.*",
        "symfony/http-client": "5.1.*",
        "symfony/intl": "5.1.*",
        "symfony/mailer": "5.1.*",
        "symfony/mime": "5.1.*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/notifier": "5.1.*",
        "symfony/process": "5.1.*",
        "symfony/property-access": "5.1.*",
        "symfony/property-info": "5.1.*",
        "symfony/security-bundle": "5.1.*",
        "symfony/serializer": "5.1.*",
        "symfony/string": "5.1.*",
        "symfony/translation": "5.1.*",
        "symfony/twig-bundle": "5.1.*",
        "symfony/validator": "5.1.*",
        "symfony/web-link": "5.1.*",
        "symfony/yaml": "5.1.*",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
    },
    "require-dev": {
        "symfony/browser-kit": "^5.1",
        "symfony/css-selector": "^5.1",
        "symfony/debug-bundle": "^5.1",
        "symfony/maker-bundle": "^1.0",
        "symfony/phpunit-bridge": "^5.0",
        "symfony/var-dumper": "^5.1"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": "true",
            "require": "5.1.*"
        }
    }
}
@kgrycuk
Copy link
Author

kgrycuk commented Aug 31, 2020

I already investigated a bit.

The Doctrine\ORM\EntityManager implements the Doctrine\ORM\EntityManagerInterface.

The Doctrine\ORM\EntityManagerInterface extends the Doctrine\Persistence\ObjectManager.

So technically, an EntityManager object should suffice as an ObjectManager, and if you go through the vendor folder and replace the use statements so that an EntityManager object is expected, the bundle will work. You will also have to replace use statements for things like lifeCycleEvents too though.

One thing I don't know about is the difference between
Doctrine\Common\Persistence\ObjectManager and Doctrine\Persistence\ObjectManager

@mmucklo
Copy link
Owner

mmucklo commented Sep 1, 2020

ok, let me take a look.

mmucklo added a commit that referenced this issue Sep 1, 2020
@mmucklo
Copy link
Owner

mmucklo commented Sep 1, 2020

@kgrycuk Please try now?

@Mycw1991
Copy link

Mycw1991 commented Sep 1, 2020

@mmucklo I also got the issue @kgrycuk got. I upgraded to version 6.3.0 of this bundle but got the following error :

In DoctrineJobTimingManager.php line 14:

  Argument 1 passed to Dtc\QueueBundle\Doctrine\DoctrineJobTimingManager::__construct() must be an instance
  of Doctrine\Common\Persistence\ObjectManager, instance of Doctrine\ORM\EntityManager given, called in /var
  /www/html/tmp/cache/dev/ContainerH63EYeG/getDtcQueue_Manager_JobTiming_OrmService.php on line 25

Removing the typehint on $objectManager in both BaseDoctrineJobManager.php & DoctrineJobTimingManager.php solves the error.

After that when I tried to create a job I got the following error

  Argument 1 passed to Dtc\QueueBundle\Doctrine\DtcQueueListener::prePersist() must be an instance of Doctrine\Common\Persistence\Event\LifecycleEventArgs, instance of Doctrine\ORM\Event\LifecycleEventArgs given, called in /var/www/html/vendor/symfony/doctrine-bridge/ContainerAwareEv
  entManager.php on line 58

I made a fork this solve this and the errors above : master...Mycw1991:master

Can you please adopt these changes or let me know if another solution is better?

mmucklo added a commit that referenced this issue Sep 1, 2020
@mmucklo
Copy link
Owner

mmucklo commented Sep 1, 2020

@Mycw1991 I made a few updates, could you try now?

@kgrycuk
Copy link
Author

kgrycuk commented Sep 1, 2020

after a composer update, php bin/console works just fine.

@Mycw1991
Copy link

Mycw1991 commented Sep 1, 2020

@mmucklo I can confirm that there are no errors on 6.3.1 . Thank you for your quick response.

@nico-dangerous
Copy link

Hi,

I got this problem with 6.3.1.
mmucklo/grid-bundle 7.1.0
mmucklo/queue-bundle 6.3.1

Argument 1 passed to Dtc\GridBundle\Grid\Source\AbstractDoctrineGridSource::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of Doctrine\ORM\EntityManager given, called in /home/vagrant/iam/vendor/mmucklo/queue-bundle/ORM/LiveJobsGridSource.php on line 29

@mmucklo
Copy link
Owner

mmucklo commented Nov 9, 2020

@nico-dangerous Could you confirm if the recently committed fix in 6.3.3 works?

@nico-dangerous
Copy link

nico-dangerous commented Nov 9, 2020

Hi,

The error is gone.

But I have a new one :

Argument 1 passed to Dtc\GridBundle\Manager\GridSourceManager::setRegistry() must be an instance of Doctrine\Common\Persistence\AbstractManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Regist   
  ry given

Maybe I should open an issue in dtc grid bundle repo ?

@mmucklo
Copy link
Owner

mmucklo commented Nov 10, 2020

@nico-dangerous - Okay, I made another adjustment, could you test now?

@mmucklo mmucklo closed this as completed May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants