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

Fix Hidden fields triggering error when using getSingleScalarResult() #8340

Conversation

Mediagone
Copy link
Contributor

Using HIDDEN fields in a request was causing the "unicity" check to fail and throw a NonUniqueResultException, because we were counting raw data instead of counting gathered row data.

See #4257 for original issue.

PS: sorry if I've done something wrong in the contribution procedure, it's my first pull request :)

Fixes doctrine#4257
HIDDEN fields was causing the "unicity" check to fail (NonUniqueResultException), because we was counting raw data instead of gathered row data.
@Mediagone
Copy link
Contributor Author

I didn't add "use function" statements because there was none in the original file, but I see errors in the commit.
Should I add them?

@beberlei
Copy link
Member

@Mediagone i don't understand what you mean with HIDDEN fields? This behavior here is the same that DBAL and by extension PDO have when you use Statement->fetchColumn() on a row with more results. It returns just the first one, and that is to be expected at the moment.

If we want this to change, it would be a BC break.

@Mediagone
Copy link
Contributor Author

Mediagone commented Nov 25, 2020

Hi @beberlei , let's take this example:

SELECT 
  COUNT(u.id) AS count, 
  (u.posts_count + u.likes_count) AS HIDDEN score
FROM User u
HAVING score > 10

In this case, getScalarResult() will return an array of 1 result ("count"), because "score" is only used internally and not returned since it uses the HIDDEN DQL keyword.
However, getSingleScalarResult() will throw a NonUniqueResultException because it counts all selected fields, including hidden ones, despite the final result will discard hidden fields and return a single scalar.

@Mediagone
Copy link
Contributor Author

Tests updated 🙂

Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

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

I'd like to see another reviewer checking the changes and if the tests are sufficient.

@beberlei beberlei added this to the 2.7.6 milestone Dec 6, 2020
@beberlei beberlei merged commit d83c0a6 into doctrine:2.7 Dec 6, 2020
@beberlei
Copy link
Member

beberlei commented Dec 6, 2020

thank you

@Mediagone Mediagone deleted the fix/#4257-single-scalar-result-and-hidden-field branch December 6, 2020 11:12
greg0ire pushed a commit to greg0ire/doctrine-orm that referenced this pull request Dec 1, 2021
…doctrine#8340)

* Fix Hidden fields triggering error when using getSingleScalarResult()

Fixes doctrine#4257
HIDDEN fields was causing the "unicity" check to fail (NonUniqueResultException), because we was counting raw data instead of gathered row data.

* Fix Coding Standards (7.4)

* Fix Coding Standards (7.4) #2

* Fix Coding Standards (7.4) - Fix whitespaces

* Fix Coding Standards (7.4) - Fix whitespaces in tests

* Fix Coding Standards (7.4) - Fix more things

* Refactor tests into separate methods

* Fix Coding Standards (7.4) - Equals sign not aligned with surrounding assignments
greg0ire pushed a commit that referenced this pull request Dec 1, 2021
…#8340)

* Fix Hidden fields triggering error when using getSingleScalarResult()

Fixes #4257
HIDDEN fields was causing the "unicity" check to fail (NonUniqueResultException), because we was counting raw data instead of gathered row data.

* Fix Coding Standards (7.4)

* Fix Coding Standards (7.4) #2

* Fix Coding Standards (7.4) - Fix whitespaces

* Fix Coding Standards (7.4) - Fix whitespaces in tests

* Fix Coding Standards (7.4) - Fix more things

* Refactor tests into separate methods

* Fix Coding Standards (7.4) - Equals sign not aligned with surrounding assignments
greg0ire pushed a commit that referenced this pull request Dec 1, 2021
…#8340)

* Fix Hidden fields triggering error when using getSingleScalarResult()

Fixes #4257
HIDDEN fields was causing the "unicity" check to fail (NonUniqueResultException), because we was counting raw data instead of gathered row data.

* Fix Coding Standards (7.4)

* Fix Coding Standards (7.4) #2

* Fix Coding Standards (7.4) - Fix whitespaces

* Fix Coding Standards (7.4) - Fix whitespaces in tests

* Fix Coding Standards (7.4) - Fix more things

* Refactor tests into separate methods

* Fix Coding Standards (7.4) - Equals sign not aligned with surrounding assignments
greg0ire pushed a commit that referenced this pull request Dec 1, 2021
…#8340)

* Fix Hidden fields triggering error when using getSingleScalarResult()

Fixes #4257
HIDDEN fields was causing the "unicity" check to fail (NonUniqueResultException), because we was counting raw data instead of gathered row data.

* Fix Coding Standards (7.4)

* Fix Coding Standards (7.4) #2

* Fix Coding Standards (7.4) - Fix whitespaces

* Fix Coding Standards (7.4) - Fix whitespaces in tests

* Fix Coding Standards (7.4) - Fix more things

* Refactor tests into separate methods

* Fix Coding Standards (7.4) - Equals sign not aligned with surrounding assignments
derrabus added a commit to derrabus/orm that referenced this pull request Dec 31, 2021
* 2.10.x:
  Bump PHPStan & Psalm (doctrine#9303)
  Removing list "Lifecycle Events" (doctrine#9243)
  Drop unneeded backslashes
  Fix Hidden fields triggering error when using getSingleScalarResult() (doctrine#8340)
  Findby joined lookup (doctrine#8285)
derrabus added a commit to derrabus/orm that referenced this pull request Dec 31, 2021
* 2.10.x:
  Bump PHPStan & Psalm (doctrine#9303)
  Removing list "Lifecycle Events" (doctrine#9243)
  Drop unneeded backslashes
  Fix Hidden fields triggering error when using getSingleScalarResult() (doctrine#8340)
  Findby joined lookup (doctrine#8285)
derrabus added a commit to derrabus/orm that referenced this pull request Dec 31, 2021
* 2.11.x:
  Bump PHPStan & Psalm (doctrine#9303)
  Removing list "Lifecycle Events" (doctrine#9243)
  Drop unneeded backslashes
  Fix Hidden fields triggering error when using getSingleScalarResult() (doctrine#8340)
  Findby joined lookup (doctrine#8285)
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

Successfully merging this pull request may close these issues.

3 participants