Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
Symfony version | 3.3.10 |
Hello.
Recently I've found very unique bug. Generally speaking doctrine instead of passing ID of entity to query, pass whole object as a parameter (Look on query 3)
This behavior is strange and a lot of condition has to be met. Here is an list:
-
Create and use repository service (instead of using
doctrine->getRepository()
https://github.com/mimol91/doctrine-sf-bug/blob/master/app/config/services.yml#L18 -
Create service which depends on registered repository https://github.com/mimol91/doctrine-sf-bug/blob/master/app/config/services.yml#L13
-
Create doctrine listener (can do nothing)
-
Use sub requests.
Observations
-
I think it may be somehow related with sub request: in this case team is serialized, so in teamSelectController Doctrine is not manage it. (In this case why it works using
this->getDoctrine()->getRepository()->getTeamsCount($club)
) ? -
Removing
->select('COUNT (t.id)')
brings back normal behavior -
I was trying to debug:
ClassMetadataFactory::hasMetadataFor
return false. -> Thus whyQuery::processParameterValue
return object instead of scalar. -
After removing
doctrine/doctrine-migrations-bundle
from composer vendors. Symfony starts to shows error:
Circular reference detected for service "doctrine.orm.default_entity_manager", path: "doctrine.orm.default_entity_manager -> doctrine.orm.default_entity_listener_resolver -> core.repo.team".
Why it does not show with doctrine-migrations-bundle
?? (it does not have to be even registered appKernel). This circular reference is probably indirect reason of strange behavior.
Some more explanation how it works / use case:
I am working on application for sport club. Each of club have own domain. Each club can have multiple teams. If club has more than two team, application display drop down on each page, which you can use to switch between teams (data is displayed based on selected team 'context'). After selecting team, information about team id is saved to session
I am using PrimaryTeamResolver which resolve which team should be used ( 1- either get data from session, 2- find club's team with 'primary' attribute set to true 3 it there is no any 'primary' team within club provide team which the smallest id)
TeamPrimaryListener is used to assure that only one 'primary' team is selected (On marking team as primary, set this attribute to false for other teams)
How to recreate:
If you want to recreate a bug, please clone repository https://github.com/mimol91/doctrine-sf-bug. Import database from /BUG directory and go to 127.0.0.1/gwarek
Application works by fetching Club
in IndexController
and its first Team
and pass this data to Twig, which then call TeamSelectController
to render from which allows to change 'team context'
Goal
My main goal behind reporting this issue, is to help to find a reason why it happens. It is probably related with doctrine, but I do not know can I give them more 'useful' info how to recreate it.
Let me know if I can help you in anyway to solve this mystery 'bug'