mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
[PR #12183] [MERGED] Paginator with output walker returns count 0 when the query has previously been executed #13549
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/doctrine/orm/pull/12183
Author: @mpdude
Created: 10/1/2025
Status: ✅ Merged
Merged: 10/27/2025
Merged by: @greg0ire
Base:
2.20.x← Head:paginator-confused-result-set-mapping-initialized📝 Commits (5)
3e34b8eAdd a test to reproduce the issuee7e2fefFix creation of the count query, to that a new RSM is being created4372595Fix CSc2b844dUpdate src/Tools/Pagination/Paginator.php828b06eUpdate the DQL walker cookbook example📊 Changes
3 files changed (+73 additions, -4 deletions)
View changed files
📝
docs/en/cookbook/dql-custom-walkers.rst(+11 -3)📝
src/Tools/Pagination/Paginator.php(+16 -1)➕
tests/Tests/ORM/Functional/Ticket/GH12183Test.php(+46 -0)📄 Description
When the
Paginatorcreates the dedicated count query, it starts with a clone of the query underlying the pagination.If that query has previously been executed, it contains a result set mapping (RSM) in the
AbstractQuery::$_resultSetMappingproperty. That RSM may have been provided by the user, or, more probably, will have been created by the DQL parser when the query was first analyzed.Either way, the RSM does not match or accurately reflect the actual count query. The count query modifies at least the select clause through either an output or a tree walker. That change needs to be reflected in the RSM for hydration to work correctly.
In the output walker case, the code in
Paginator::getCountQueryeven creates and sets a new RSM explicitly. In the tree walker case, the RSM was not taken care of.My current suggestion is not to clone the query in preparation for counting the items, but instead create a copy of the query to start with. This will leave the RSM as
nullin the new query.I was wondering whether there might be any good reasons to keep the existing RSM since it might have been provided by the user. But, since we modify the query and completely replace the select clause with the scalar expression for counting the rows, I don't see how any pre-existing RSM could apply to the new query.
Nevertheless, reviewers might want to take a step back and consider other options we might have to fix this:
Query::__clonemarks a query as dirty when it is cloned. Should a dirty query drop its RSM to make sure it is re-created upon the nextparse()?$_resultSetMappingproperty and keep/use them unconditionally, but treat parser-derived RSMs differently and forget about them as soon as the query gets dirty?🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.