mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Annotation receives array of paths instead of reader #6963
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 @ppaulis on GitHub (Apr 20, 2022).
Bug Report
2.12.0 doesn't work with
doctrine/doctrine-orm-module: 5.1.0.Summary
After upgrading from 2.11.1 to 2.12.0, I'm experiencing the following issue:
Current behavior
Reading Metadata no longer works through the
doctrine-orm-module.In the following line:
d550364431/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php (L82)$this->readerno longer contains the reader, but the array of paths:Currently, my best guess is, that this class is instanciated with a missing first parameter. And the paths are then passed as first parameter in the readers place.
How to reproduce
doctrine/doctrine-orm-module: 5.1.0doctrine/orm: 2.12.0PHP : 8.0.16
@ppaulis commented on GitHub (Apr 20, 2022):
Seems that this is happening here:
61dc07830d/src/Service/DriverFactory.php (L75-L76)In my case,
$classhas the valueDoctrine\ORM\Mapping\Driver\AnnotationDriver, but for this to work, it should probably beDoctrine\Persistence\Mapping\Driver\AnnotationDriver(which is deprecated).I'll try to prepare a fix asap. @Ocramius
@ppaulis commented on GitHub (Apr 20, 2022):
has already been reported here: https://github.com/doctrine/DoctrineModule/issues/774
Suggested PR : https://github.com/doctrine/DoctrineModule/pull/775
@greg0ire commented on GitHub (Apr 20, 2022):
Did you also upgrade (voluntarily or not)
doctrine/persistence? It just got a major release.@ppaulis commented on GitHub (Apr 20, 2022):
@greg0ire not possible as this is a Laminas project, and
doctrine/doctrine-orm-moduleis not (yet) compatible todoctrine/persistence: 3.0.0@greg0ire commented on GitHub (Apr 20, 2022):
This is caused by a BC-break I introduced in https://github.com/doctrine/orm/pull/9587, where the ORM annotation driver no longer extends the one from persistence 😬
Wrong assumption, @greg0ire from the past!
@Ocramius commented on GitHub (Apr 21, 2022):
Ref: https://github.com/Roave/psr-container-doctrine/issues/70
@Ocramius commented on GitHub (Apr 21, 2022):
Suggestion on my end is to revert the offending (involuntary) BC break for now, and release
2.12.1with that fix.That means re-introducing some tech debt, and planning its removal for
3.0.x.@ppaulis commented on GitHub (Apr 21, 2022):
@Ocramius @greg0ire As the deprecated AnnotationDriver has been removed in
doctrine/persistence: 3.0, does this mean, that we need to change the dependency"doctrine/persistence": "^2.4 || ^3"to"doctrine/persistence": "^2.4?@greg0ire commented on GitHub (Apr 21, 2022):
In ORM? I figured it does cause an issue while trying to revert: https://github.com/doctrine/orm/pull/9670, but I think conditionally defining the class based on some condition should allow us to retain compatibility with Persistence 3.
@Ocramius commented on GitHub (Apr 21, 2022):
Depends if the consumer would observe an API change or not: remember that any API change caused by third-party packages being installed or not is still an API change -> BC break.
EDIT: anyway, I suggest:
@greg0ire commented on GitHub (Apr 21, 2022):
The API change would occur if a consumer was not pinning
doctrine/persistenceto 2, unlike here: https://github.com/doctrine/DoctrineModule/blob/5.2.x/composer.json#L53I think it's fair to have this BC break in the case persistence is upgraded to 3, because if you depend on the annotation driver and it extends the API from persistence, then you depend on persistence.
I've made an attempt at the revert because it sounded like it would be fast, but it looks like we already built on top of this: https://github.com/doctrine/orm/pull/9670 , so it won't be a simple revert I'm afraid.
@Ocramius commented on GitHub (Apr 21, 2022):
The referenced symbol (
Doctrine\ORM\Mapping\Driver\AnnotationDriver) is the one in indoctrine/orm: if its structure changes due to inherited API, it is a BC break also indoctrine/orm. Changing signature ofAnnotationDriverbased on the third-party package is still a BC break.A suggestion could be to:
doctrine/orm, keepDoctrine\ORM\Mapping\Driver\AnnotationDriverparity (should be possible to check this withroave/backward-compatibility-check)Doctrine\ORM\Mapping\Driver\AnnotationDrivercompletely: call it "dead"AnnotationDriver(completely different name, likeAnnotationMappingDriveror such) and point new consumers to that@greg0ire commented on GitHub (Apr 21, 2022):
if (!class_exists(TheClass)) { require_once 'some_file.php'; }reminds me of https://dev.to/greg0ire/how-to-deprecate-a-type-in-php-48cf but maybe in our case it's unlikelyAnnotationDriveris ever used in a signature.AnnotationDriverbecause it's ultimately going to be removed, but if this has to be done forAttributeDriveras well, then it means we will break the naming consistency betweenXMLDriver,YamlDriver,PHPDriveretc.At that point I think we would be better off merging either https://github.com/doctrine/DoctrineModule/pull/776 or https://github.com/doctrine/DoctrineModule/pull/775 and hope this is the only legitimate issue caused by this BC break.
@Ocramius commented on GitHub (Apr 22, 2022):
Correct: this allows moving to newer
doctrine/persistencewithout breaking BC, but needs to be carefully checked.Consistency is still secondary to BC, heh.
The BC break is still there for anyone using
doctrine/orm: remember that these modules just happen to be public projects that we are aware of, and are direct consumers of the ORM, but the source of all this is the BC break, not the consumers. All consumers will have to adapt once a new major of the ORM is out, but until then, some cruft needs to stay, for the sake of stability.@greg0ire commented on GitHub (Apr 22, 2022):
The cure seems worse than the disease here. I agree that you have to think of the consumers, but they are usually pretty vocal when it comes to BC-breaks, and so far this is the only complaint we got about it. I asked other maintainers what they thought and tried hard not to steer them in any direction, and they pointed out that the code in the module will need to be fixed for the new class anyway. I think we should merge a quick fix, and ask the maintainers of the Laminas integration to rethink that piece of code entirely, and be done with it. Same goes for https://github.com/Roave/psr-container-doctrine/blob/3.6.x/src/DriverFactory.php#L52
Note that both pieces of code got worse when
AttributeDriverwas introduced, and that things will likely continue to get worse every time we touch this area in ORM.@Ocramius commented on GitHub (Apr 22, 2022):
I'm not sure if my message is getting through:
Roave/*and thedoctrine/*Moduleare a spit in an ocean of consumers.As I already mentioned, code will be improved where/when there is time to do so (especially when required in a new major release of
doctrine/orm), but until then, BC is sacred. If you break BC, declare it with a new major, and consumers will adapt when they support the new version range.@greg0ire commented on GitHub (Apr 22, 2022):
I don't doubt that, what I doubt is that there are that many type checks on
AnnotationDriver. So far this has only be reported to happen inDoctrineModuleandRoave/psr-container-doctrine, and it seems easier to fix both packages than implement a fix indoctrine/orm. I can certainly dedicate some time to writing a fix forpsr-container-doctrineonce we agree on one forDoctrineModule.@Ocramius commented on GitHub (Apr 22, 2022):
Be my guest in fixing symptoms.
Seriously, just fix the BC break, and all is good 😛
I'll gladly accept patches that improve the PSR integration too, but beware that this still broke all released versions anyway.
@greg0ire commented on GitHub (Apr 22, 2022):
I would if it wasn't that hard, but I'm more confident in fixing the symptoms as you say 😅 Hopefully people who upgrade the ORM will also be able to upgrade both other packages 🤞
@derrabus commented on GitHub (Apr 22, 2022):
While I agree that changing the inheritance chain is a potential BC break, I'm not sure I 100% follow the argument of the BC break here. The code in question assumes that all driver classes that require an annotation reader are child classes of the
AnnotationDriverclass from doctrine/persistence and vice versa. This assumption did fail previously (doctrine/DoctrineModule#728), it fails now and is doomed to fail again.That being said, we have to acknowledge that this flawed piece of code has existed for roughly a decade now and that we would probably need to patch multiple legacy branches of DoctrineModule because applications that use older PHP versions than 7.4 have to pin DoctrineModule to an old version while still being able to upgrade to the latest ORM.
My proposal to tackle the issue: #9671
We would still need to change DoctrineModule though, but we can do so when working on making it compatible with Persistence 3.
@Ocramius commented on GitHub (Apr 22, 2022):
Awesome, thanks!