Fix some Doctrine runtime exceptions#4695
Conversation
|
I only see the exceptions in the debugger, but according to the information which I found (partially with AI support) the previous code cannot work. Note that there are more similar code locations which also might. need a fix. |
Doctrine ORM expects an entity class, not an interface. Doctrine cannot instantiate or query interfaces—only concrete classes. The mapping in PluginManager.php only applies to dependency injection and factory-based object creation, not to Doctrine ORM DQL queries. Signed-off-by: Stefan Weil <sw@weilnetz.de>
EreMaijala
left a comment
There was a problem hiding this comment.
Doctrine can resolve the interfaces to the target classes using its ResolveTargetEntityListener that's initialized in module/VuFind/src/VuFind/Db/EntityManagerFactory.php. While it uses an exception internally to trigger the fallback loader, the exception won't be passed on if the interface gets resolved to an actual class.
If this was really a problem, VuFind's database functionality would not work at all. The interfaces are used everywhere.
There is a similar case of runtime exceptions happening for command-specific arguments in console utilities, and it's not a real problem either. While it can be argued that using exceptions for normal control flow is inappropriate, VuFind also does that internally e.g. to trigger an authentication request.
demiankatz
left a comment
There was a problem hiding this comment.
Please see the conversation thread on #2233 about this issue -- this is the way it is by design, and it does work correctly. I believe that we should probably close this PR without changes, but if you want to discuss the Doctrine implementation in more detail, please feel free to join a Community Call (there is one today at 13:00 GMT).
As @EreMaijala says, if we wanted to change our approach to DQL generation, we would have to make many more changes than the ones in this PR. But I do not think we want to change it, based on my comments in the thread linked above.
Doctrine ORM expects an entity class, not an interface. Doctrine cannot instantiate or query interfaces—only concrete classes.
The mapping in PluginManager.php only applies to dependency injection and factory-based object creation, not to Doctrine ORM DQL queries.