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] Fixed submitting invalid ids when using queries with limit #34900

Merged
merged 1 commit into from Dec 15, 2019

Conversation

HeahDude
Copy link
Contributor

@HeahDude HeahDude commented Dec 9, 2019

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #31559
License MIT
Doc PR ~

@@ -55,6 +55,26 @@ public function getEntities()
*/
public function getEntitiesByIds($identifier, array $values)
{
if (null !== $this->queryBuilder->getMaxResults()) {
$metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other way I see to fix this is to throw an exception here and to catch it in the DoctrineChoiceLoader to let it fall back on loading the list. But I would prefer to have it part of the EntityLoaderInterface contract rather than leaking too much in there.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Dec 9, 2019
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Dec 11, 2019

We could also consider the original issue as unsupported: doing a LIMIT query for a choice list looks very strange to me.
We'd better reduce complexity rather than increasing it...

@HeahDude
Copy link
Contributor Author

I agree, I also felt that way. But we might consider some kind of "paginated" choices as a valid use case, or whatever reason leading to open the related issue.
Moreover is there any reason to forbid it since this has the cost of a BC break?

Finally the expected behavior covered here by the test seems a legit bug fix to me, but we could still deprecate that if in master and get back to simple code in 6.0, also documenting the limitations this time. WDYT?

@HeahDude
Copy link
Contributor Author

HeahDude commented Dec 11, 2019

Also note that forbidding the usage in such case does lead to adding complexity and/or throwing or new specialized exception form the entity loader to catch in the DoctrineChoiceLoader as I propose in my comment above.

@HeahDude
Copy link
Contributor Author

If we were to forbid it purely and simply I think this should better be done when normalizing the query_builder option to throw as soon as possible a configuration exception.

@fabpot
Copy link
Member

fabpot commented Dec 15, 2019

Thank you @HeahDude.

fabpot added a commit that referenced this pull request Dec 15, 2019
…ueries with limit (HeahDude)

This PR was merged into the 3.4 branch.

Discussion
----------

[DoctrineBridge] Fixed submitting invalid ids when using queries with limit

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #31559 <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | ~
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->

Commits
-------

09bb1e4 [DoctrineBridge] Fixed submitting invalid ids when using queries with limit
@fabpot fabpot merged commit 09bb1e4 into symfony:3.4 Dec 15, 2019
@fabpot fabpot mentioned this pull request Dec 19, 2019
@HeahDude HeahDude deleted the fix-doctrine-loader-optim branch December 19, 2019 17:34
@fabpot fabpot mentioned this pull request Dec 19, 2019
This was referenced Jan 21, 2020
$metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities()));

foreach ($this->getEntities() as $entity) {
if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok with strict in_array? There is comming string variable from EntityType, but getIdentifierValues return integer from entity (if I am using strict_types). Then I get always error by comparing string vs integer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jirinapravnik, I've opened #35609 to fix this.

fabpot added a commit that referenced this pull request Feb 7, 2020
…offset (HeahDude)

This PR was merged into the 3.4 branch.

Discussion
----------

[DoctrineBridge] Fixed submitting ids with query limit or offset

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #34900 (comment) <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | ~ <!-- required for new features -->
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->

Commits
-------

9bb1940 [DoctrineBridge] Fixed submitting ids with query limit or offset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants