mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Error thrown when setting up Doctrine ORM #6776
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @filiptrplan on GitHub (Jul 2, 2021).
On a freshly installed Doctrine ORM I tried to setup the EntityManager like so:
Only to get the following error:
My composer.json:
I also tried installing the
symfony/cacheanddoctrine/cachepackages separately withcomposer requirebut I got the same error.I'm running PHP version 7.3.28
This should be the piece of code throwing the exception:
My IDE also highlights those classes and some others as missing.



@greg0ire commented on GitHub (Jul 2, 2021):
Can you find either class in your vendor directory or not?
@filiptrplan commented on GitHub (Jul 2, 2021):
After some browsing, I couldn't locate them either. Seems like a dependency issue but I've got no idea how to solve it.
@greg0ire commented on GitHub (Jul 2, 2021):
If you cannot locate them, then I'm afraid your
composer requiredid not work at all. What did it say?@filiptrplan commented on GitHub (Jul 3, 2021):
But there are only some of the classes missing. Just the ones I
screenshotted. Some other cache classes have been installed. I also tried
updating composer and reinstalling everything. Can you maybe try composer
install with my composer.json and see if it works?
On Fri, Jul 2, 2021, 20:49 Grégoire Paris @.***> wrote:
@greg0ire commented on GitHub (Jul 3, 2021):
Sure, why not?
@greg0ire commented on GitHub (Jul 3, 2021):
Well, it works for me after installing
symfony/cache. Be wary thatdoctrine/cache2 is just an empty shell, becausedoctrine/cacheis being sunset.@filiptrplan commented on GitHub (Jul 4, 2021):
Could you post the composer.json that works for you? I'll try to wipe the vendor folder and cache and install it again with a working composer.json.
@greg0ire commented on GitHub (Jul 4, 2021):
Here you go:
@dopeh commented on GitHub (Aug 3, 2021):
I'm running into the same issue while on doctrine/orm v2.9.3. My composer upgraded doctrine/cache to v2.1 (from v1.11.3) as this is allowed in the composer.json of doctrine/orm (https://github.com/doctrine/orm/blob/2.9.x/composer.json#L24).
But doctrine/cache v2.1 is incompatible with doctrine/orm v2.9.3 because of the hard-check on
ArrayCache(see https://github.com/doctrine/orm/blob/2.9.x/lib/Doctrine/ORM/Tools/Setup.php#L183), which class has been removed from doctrine/cache v2.1.My current work-around is to add an extra constraint on doctrine/cache v1 but it seems to me doctrine/orm v2.9 should not be marked as compatible with doctrine/cache v2.1 to prevent this upgrade from happening.
@greg0ire commented on GitHub (Aug 3, 2021):
The check is about class existence, so, not sure what a hard check is, but there for sure isn't a hard dependency here. What is supposed to happen is
symfony/cache(or any other implementation of the PSR ?) is supposed to take over if you installdoctrine/cachev2I would still love to get a piece of code that reliably reproduces the issue.
@filiptrplan commented on GitHub (Aug 3, 2021):
It's not a dependency, but it is used in the code.
On Tue, Aug 3, 2021, 18:03 Grégoire Paris @.***> wrote:
@greg0ire commented on GitHub (Aug 3, 2021):
… in a
class_exists()call, right?@filiptrplan commented on GitHub (Aug 4, 2021):
Yeah, it throws an exception if it doesn't exist. That's the reason for the error.
@greg0ire commented on GitHub (Aug 4, 2021):
It does so as a way to detect if you have doctrine/common 1, or symfony/cache installed. If neither is installed, it throws with a very explicit error message. If this does not work as expected, please provide a repository on github that allows to reproduce your issue reliably.
@dopeh commented on GitHub (Aug 4, 2021):
I would argue that, in fact, it is a hard dependency. The
class_exists()call isn't, but because it throws a RuntimeException if it doesn't exist.I think filiptrplan is using the Getting started example on the doctrine website, which is now broken (https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/tutorials/getting-started.html#obtaining-the-entitymanager). You can't call
Setup::createYAMLMetadataConfigurationif doctrine/cache 2.1 is loaded, because it will always throw a RuntimeException as the ArrayCache class does not exist, even if you don't use it yourself. So you would need to manually pin doctrine/cache to a compatible version, even for the example to work.In addition, any existing projects also run into this, where they are being upgraded to an incompatible doctrine/cache version while still on the same ORM version. Perhaps it makes sense to keep this doctrine/cache upgrade to a next major/minor release for doctrine/orm because it breaks existing code (even the examples).
Edit: I just tried running the example from the docs in a clean project, and can confirm that no longer works. Since it does not pin a specific version of the cache, it will download doctrine/cache v2.1 causing the
Setup::createYAMLMetadataConfiguration()to throw the RuntimeException. So I think there is a real issue if even the examples on the website no longer work out of the box.@greg0ire commented on GitHub (Aug 4, 2021):
Please push that project on a public github repo.
@dopeh commented on GitHub (Aug 4, 2021):
See https://github.com/dopeh/doctrine-orm-example
The actual hard dependency is here I think. If no cache is provided, doctrine/orm v2.9 will automatically load an ArrayCache when setting up. This is currently prevented by the class_exists check, which is good, but then an alternative should be loaded from doctrine/cache 2.1 I think.
@greg0ire commented on GitHub (Aug 4, 2021):
Ah thanks a lot, I should be able to take a look later :)
From what I gather, the issue might be that https://github.com/doctrine/orm/blob/2.9.x/UPGRADE.md#minor-bc-break-setup-tool-needs-cache-implementation is not sufficient and that the official docs need to be upgraded too.
Does applying https://github.com/doctrine/orm/blob/2.9.x/UPGRADE.md#minor-bc-break-setup-tool-needs-cache-implementation fix your issue?
@greg0ire commented on GitHub (Aug 4, 2021):
Ok so I tried your example repository. I'm getting the following crash
I have read the error message. Now, let's compare it with what's installed.
Indeed, I have
doctrine/cache, but v2, and I don't havesymfony/cache. I deserve this error message.The next steps are clear to me: I should either downgrade to
doctrine/cache, or, and that's better, installsymfony/cache(withcomposer require symfony/cache)After doing so, there is no crash anymore.
Is any of this unclear to anyone here?
In case you want to experience the absence of crash for yourself, I made a PR at https://github.com/dopeh/doctrine-orm-example/pull/1
👍 That might be possible without explicitly recommending
symfony/cache, by requiringpsr/cache-implementationfromdoctrine/cache. Let me do a PR with that.@greg0ire commented on GitHub (Aug 4, 2021):
Actually no, bad idea, it would solve your specific issue because the SetupTool can work with either
doctrine/cachev1 orsymfony/cache, but not with anotherpsr/cache-implementationpackage.@dopeh commented on GitHub (Aug 4, 2021):
To be fair, a new developer starting a new project with doctrine/orm from scratch does not deserve that.
Please note that the code in my repo was a copy/paste from the getting started docs located here, no more than that. The current Getting Started example from the documentation doesn't work, and instead requires the developer to read an error message and fix it manually by including an extra package (or downgrading one). I don't believe that's a good introduction to an excellent project that doctrine/orm is.
I understand you are trying to stay away of being dependent on a cache dependency, while one is still needed for setting up. So I don't have any other suggestion to fix this, except for applying your proposed PR against the getting started docs instead (https://github.com/doctrine/orm/pull/8883).
@grzeczko commented on GitHub (Sep 9, 2021):
In your composer.json, add the following:
"doctrine/cache": "~1.11.3",@abass-dev commented on GitHub (Sep 11, 2021):
It works for me!
The error is already explained when you have typed a command
E.g:
bash ./vendor/bin/doctrine listFatal error: Uncaught RuntimeException: Setup tool cannot configure caches without doctrine/cache 1.11
@J4bbi commented on GitHub (Oct 27, 2021):
I came here as a dev that rarely uses php and ran into exactly these confusing problems.
I started the docs to set up a simple boilerplate orm setup with mariadb. The online html tutorial isn't in sync with the rst so still more faff.