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

"The query returned a row containing multiple columns." using HYDRATE_SINGLE_SCALAR with a hidden column #9209

Closed
Cartman34 opened this issue Nov 29, 2021 · 8 comments

Comments

@Cartman34
Copy link

Bug Report

Q A
BC Break no
Version 2.10.1

Summary

While trying to get a list of ID for one entity, I tried to use getResult(AbstractQuery::HYDRATE_SINGLE_SCALAR), one column is visible, the other is hidden, it seems an issue for Doctrine but it should work.

Current behavior

Doctrine throws exception about multiple column selected while using HYDRATE_SINGLE_SCALAR but only one is visible, the other is hidden.
The error is

The query returned a row containing multiple columns. Change the query or use a different result function like getScalarResult().

How to reproduce

Select 2 columns, one visible, other is hidden.
Get a list of first column, using getResult(AbstractQuery::HYDRATE_SINGLE_SCALAR)

$qb->select('entity.id AS id');
$qb->select('entity.id AS HIDDEN otherId');
$idList = $qb->getQuery()->getResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);

Expected behavior

I get a list of IDs with no error.

@greg0ire greg0ire reopened this Nov 30, 2021
@greg0ire
Copy link
Member

Can you please provide a stack trace? Read more on how to do so here: https://symfony.com/doc/current/contributing/code/stack_trace.html

@Cartman34
Copy link
Author

Is that you want ?

Doctrine\ORM\NonUniqueResultException:
The query returned multiple rows. Change the query or use a different result function like getScalarResult().

at vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php:32
at Doctrine\ORM\Internal\Hydration\SingleScalarHydrator->hydrateAllData()
(vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:268)
at Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(object(Result), object(ResultSetMapping), array())
(vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1169)
at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, 4)
(vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1115)
at Doctrine\ORM\AbstractQuery->execute(null, 4)
(vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:863)
at Doctrine\ORM\AbstractQuery->getResult(4)
(src/Controller/ServiceSearchController.php:184)

@greg0ire
Copy link
Member

Yes, exactly 👍

@greg0ire
Copy link
Member

So the exception comes from here:

throw new NonUniqueResultException('The query returned multiple rows. Change the query or use a different result function like getScalarResult().');
and … oh!

Duplicate of #4257 , right?

@greg0ire
Copy link
Member

Duplicate of #4257

@greg0ire greg0ire marked this as a duplicate of #4257 Nov 30, 2021
@greg0ire
Copy link
Member

greg0ire commented Nov 30, 2021

Reopening since #4257 is supposed to be fixed… @Mediagone maybe you can help with this?
@Cartman34 you will find a test case in #8340, you can maybe copy/paste/adapt it to add something that looks like what you have, thus creating a failing test case?

@greg0ire greg0ire reopened this Nov 30, 2021
@Mediagone
Copy link
Contributor

How can I know the target version into which the fix was merged?

@greg0ire
Copy link
Member

greg0ire commented Dec 1, 2021

  1. find the PR
  2. find the commit in the PR
  3. the commit page on Github shows that kind of information

Here we can see that it was merged in 2.7: d83c0a6 , but weirdly, it does not show tag information

It looks like your commit was merged in 2.7, but should have been merged in 2.7.x. I'm closing this and reopening the other issue then.

@greg0ire greg0ire closed this as completed Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants