Single column hydration returns nothing if first item is false-like #6885

Closed
opened 2026-01-22 15:40:43 +01:00 by admin · 5 comments
Owner

Originally created by @TomaszGasior on GitHub (Dec 7, 2021).

Bug Report

Q A
BC Break no
Version 2.10.3

Summary

While working on my open source app I found out that scalar column hydration does not return any value, just empty array, when first element of the results is false-like (null, 0, ''…).

How to reproduce

Do something like this but without <> NULL and <> '': 8a2b4fa0d6/src/Repository/RadioStationRepository.php (L68)

Simplified example:

return $this->createQueryBuilder('radioStation')
    ->select('DISTINCT radioStation.'.$column)
    ->getQuery()
    ->getSingleColumnResult()
;

If first item from result set is false-like, empty array is returned.

Expected behavior

I would like to get all values from the column, even something like null, ''.

Adding false !== to 6414ad4cbb/lib/Doctrine/ORM/Internal/Hydration/ScalarColumnHydrator.php (L31) kinda fixes the issue. I don't know whether Doctrine is able to return native false for DBMS-es supporting it and how to support that case if it's needed.

Originally created by @TomaszGasior on GitHub (Dec 7, 2021). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.10.3 #### Summary While working on my open source app I found out that scalar column hydration does not return any value, just empty array, when first element of the results is false-like (null, 0, ''…). #### How to reproduce Do something like this but without `<> NULL` and `<> ''`: https://github.com/TomaszGasior/RadioLista-v3/blob/8a2b4fa0d6d9fb85d83a36a00bd61d2031a1a8b3/src/Repository/RadioStationRepository.php#L68 Simplified example: ```php return $this->createQueryBuilder('radioStation') ->select('DISTINCT radioStation.'.$column) ->getQuery() ->getSingleColumnResult() ; ``` If first item from result set is false-like, empty array is returned. #### Expected behavior I would like to get all values from the column, even something like null, ''. Adding `false !==` to https://github.com/doctrine/orm/blob/6414ad4cbb898e4ae027a1a0de48b31984002dea/lib/Doctrine/ORM/Internal/Hydration/ScalarColumnHydrator.php#L31 kinda fixes the issue. I don't know whether Doctrine is able to return native `false` for DBMS-es supporting it and how to support that case if it's needed.
admin closed this issue 2026-01-22 15:40:43 +01:00
Author
Owner

@greg0ire commented on GitHub (Dec 13, 2021):

@bhushan please take a look at this 🙏

@greg0ire commented on GitHub (Dec 13, 2021): @bhushan please take a look at this :pray:
Author
Owner

@bhushan commented on GitHub (Dec 14, 2021):

@TomaszGasior are you planning to PR fix?

@bhushan commented on GitHub (Dec 14, 2021): @TomaszGasior are you planning to PR fix?
Author
Owner

@bhushan commented on GitHub (Dec 16, 2021):

@TomaszGasior https://github.com/doctrine/orm/pull/9255 does this test case makes sense or you meant something else ?

@bhushan commented on GitHub (Dec 16, 2021): @TomaszGasior https://github.com/doctrine/orm/pull/9255 does this test case makes sense or you meant something else ?
Author
Owner

@TomaszGasior commented on GitHub (Dec 16, 2021):

@bhushan Unfortunately I am not able to provide PR for now. I consider change in ScalarColumnHydrator.php as debugging hint, maybe not final solution. Yep, provided test looks good (except for lack of string with zero char about which I added comment in the PR).

@TomaszGasior commented on GitHub (Dec 16, 2021): @bhushan Unfortunately I am not able to provide PR for now. I consider change in ScalarColumnHydrator.php as debugging hint, maybe not final solution. Yep, provided test looks good (except for lack of string with zero char about which I added comment in the PR).
Author
Owner

@MrMitch commented on GitHub (Apr 15, 2022):

Hi @greg0ire @bhushan @TomaszGasior. Thank you for you work on this. I've opened PR #9663 to fix this issue. It includes a test and the fix. Let me know if there is anything else I can do to help.

@MrMitch commented on GitHub (Apr 15, 2022): Hi @greg0ire @bhushan @TomaszGasior. Thank you for you work on this. I've opened PR #9663 to fix this issue. It includes a test and the fix. Let me know if there is anything else I can do to help.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6885