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

[DoctrineBridge] Trigger a proper error when injection a service containing the entity manager in a doctrine listener #31636

Closed
Simperfit opened this issue May 27, 2019 · 5 comments
Labels
DoctrineBridge DX DX = Developer eXperience (anything that improves the experience of using Symfony)

Comments

@Simperfit
Copy link
Contributor

Simperfit commented May 27, 2019

Description

This is mainly for DX but I think if we throw a proper message when injecting a service that contains the entity manager into a doctrine listener (because this is not working) and the only errors we get is some flush errors that are linked but not really the root cause.

Example

Today something like this is thrown by Doctrine directly:

Doctrine\ORM\ORMInvalidArgumentException: Entity Pack\Domain\Model\Pack@000000001668b6260000000058419870 is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager#persist

Maybe we could throw an special error like this one:

Injecting a service that contains `EntityManagerInterface` into a service that as a listener tag is not allowed.

Tell me if this is this has more it's place into doctrinebundle.

@xabbuh xabbuh added DoctrineBridge DX DX = Developer eXperience (anything that improves the experience of using Symfony) labels May 27, 2019
@dmaicher
Copy link
Contributor

I think actually this is a bug 😉 There are multiple different EntityManager instances created - which should never happen really.

See
#28869
#30091
#30465

I think it should be resolved on DI level. If there is no proxy-bridge available then it should probably end up with a circular-reference exception or so.

@Simperfit
Copy link
Contributor Author

Simperfit commented May 27, 2019

@dmaicher That's the fix I though of, handle this at the DI level and throw a circular-reference exception specify which service is injecting in which listener.

@dmaicher
Copy link
Contributor

@Simperfit I think the fix is not necessarily EntityManager specific though. I think this scenario should be detected as a circular reference on DI level independent of Doctrine and the EntityManager if possible.

@Simperfit
Copy link
Contributor Author

cc @weaverryan You are working on this right ?

@nicolas-grekas
Copy link
Member

This should be fixed. Please report back if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DoctrineBridge DX DX = Developer eXperience (anything that improves the experience of using Symfony)
Projects
None yet
Development

No branches or pull requests

4 participants