-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Entity Annotation & EntityRepository Template causes Psalm Covariance Issues #9681
Comments
Solution 2 would basically disallow passing |
Hm, yes – seems like you're right. That's obviously not a good way to solve this, then. Do you have any other ideas on how to approach this? |
I think marking it as covariant is not ideal either, if you have a |
@derrabus I dont think so. As long as the generic repository itself doesnt use PHPDoc /**
* @extends ServiceEntityRepository<XXXX>
*/ I am in favor of Solution 2, I see no drawbacks |
@michnovka I think this is the problem, not 100% sure though because I've always used a repository class for each entity instead of using a generic repository. I'm not sure how to get around that though, |
Is this a valid concern though? Does anybody use the default EntityRepository in this case? Doesnt everybody extend on top of it for each entity? Is there any use case, where a generic Repository like EntityRepository would be passed to Entity attribute? |
As far as I checked, using solution 2 vs current situation does not break anything. Passing But adding the template to the |
Because it's possible and it's valid. It could also be a project-specific generic repository implementation that extends |
It's a bit unfortunate that #9708 got merged before we finished this discussion. I'm opening the issue again because I believe we're not done here.
Yes and it's a problem that #9708 broke that scenario. I don't feel comfortable releasing the 2.12.x branch in its current state, tbh. Regarding the idea to declare covariance on
Is there anything else apart from the |
@derrabus It looks like it may have been broken before #9708, so #9708 left that case broken but fixed the case of having a specific repository, which seems better than nothing.
I'm not sure it actually fixes the problem anyway. I think the only way to support this correctly would be to fix vimeo/psalm#7913 to allow class-strings to be templated correctly. |
You're right. The root cause if probably #9274.
Yeah, it looks like the current solution is indeed the lesser evil. 😕 |
Bug Report
When updating our
doctrine/orm
dependency to2.12.1
we experienced Psalm issues of the following kind in our CI pipeline:Summary
This is reproducible for any entity that configures a repository class using the
Entity
Annotation / Class Attribute if the repository class uses Psalm generics:The issue stems from the
Entity
Mapping annotation to require aclass-string<EntityRepository>
here:orm/lib/Doctrine/ORM/Mapping/Entity.php
Lines 28 to 31 in a552df6
This breaks due to what I believe to be covariance issues: https://psalm.dev/docs/annotating_code/templated_annotations/#template-covariance
How to reproduce
I have recreated a simplified reproduction case using the Psalm playground: https://psalm.dev/r/db2ba03745
Expected behavior
I would expect the
Entity
annotation to continue working as it did before the update.Potential Solution 1
Adding
@template-covariant T
to theEntityRepository
class DocBlock seems to resolve all Psalm issues for us. I am not 100% sure if that has any other implications, though.Side Note: We use the
ServiceEntityRepository
class provided bydoctrine-bundle
, which transparently extendsEntityRepository
- any solution for this issue thus likely also applies to that class as well (e.g. adding the@template-covariant T
there, too).Potential Solution 2
Maybe the
Entity
Attribute / Mapping Annotation could also get a generic template parameter, something like this:This also solves the Psalm issues in our codebase and seems like a less intrusive, more "correct" fix.
The text was updated successfully, but these errors were encountered: