Paginator returns incorrect IDs in getIterator when a subquery WHERE is present #7566

Closed
opened 2026-01-22 15:53:32 +01:00 by admin · 0 comments
Owner

Originally created by @pkly on GitHub (Oct 30, 2025).

Bug Report

Q A
Version 3.5.3

Observed on 3.5.2 as well, possibly before then.

Summary

We're using doctrine alongside EasyAdmin and we observed funky behavior when adding a complex filter on one of our views which then gets passed into Paginator.

The query in question can be mostly boiled down to something like this:

$query = $repo->createQueryBuilder('entity');
$subQuery = $repo->createQueryBuilder('filter');

$subQuery->select('filter.id')
    ->innerJoin('filter.identifierUses', 'identifierUseFilter')
    ->innerJoin('identifierUseFilter.identifier', 'identifierFilter')
    ->where('identifierFilter.code = :code');

$query->andWhere('entity.id IN ('.$subQuery->getDql().')');

Generated DQL in Paginator:

SELECT entity FROM MyEntity entity WHERE entity.id IN((SELECT filter.id FROM MyEntity filter INNER JOIN filter.identifierUses identifierUseFilter INNER JOIN identifierUseFilter.identifier identifierFilter WHERE identifierFilter.code = :code)) AND entity.source = :source AND entity.isArchived = 0 ORDER BY entity.id DESC

Produced SQL on count query from Paginator:

SELECT DISTINCT s0_.id AS id_0, s0_.id AS id_1
FROM my_entity s0_
WHERE s0_.id IN (
(SELECT s1_.id FROM my_entity s1_ INNER JOIN identifier_uses s2_ ON s1_.id = s2_.entity_id INNER JOIN identifiers s3_ ON s2_.identifier_id = s3_.id AND (s3_.deleted_at IS NULL) WHERE s3_.code = ?)
) AND s0_.source = ? AND s0_.is_archived = 0
ORDER BY s0_.id DESC LIMIT 20

Later produces incorrect ids, as only 1 id is expected, but 2 are returned, even though the subquery by itself is correct, I believe the error is caused by multiple columns being present in select for this query, while paginator only expects one. It seems like it's caused by LimitSubqueryWalker adding a second select statement (at least from what I checked)

Current behavior

Incorrect IDs are returned by Paginator (variable: $foundIdRows in getIterator)

Expected behavior

Correct IDs are returned.

How to reproduce

I'll try to provide a repository with example data and entities shortly if needed.

Originally created by @pkly on GitHub (Oct 30, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |-------------------------------------------- | ------ | Version | 3.5.3 Observed on 3.5.2 as well, possibly before then. #### Summary We're using doctrine alongside EasyAdmin and we observed funky behavior when adding a complex filter on one of our views which then gets passed into Paginator. The query in question can be mostly boiled down to something like this: ```php $query = $repo->createQueryBuilder('entity'); $subQuery = $repo->createQueryBuilder('filter'); $subQuery->select('filter.id') ->innerJoin('filter.identifierUses', 'identifierUseFilter') ->innerJoin('identifierUseFilter.identifier', 'identifierFilter') ->where('identifierFilter.code = :code'); $query->andWhere('entity.id IN ('.$subQuery->getDql().')'); ``` Generated DQL in Paginator: ``` SELECT entity FROM MyEntity entity WHERE entity.id IN((SELECT filter.id FROM MyEntity filter INNER JOIN filter.identifierUses identifierUseFilter INNER JOIN identifierUseFilter.identifier identifierFilter WHERE identifierFilter.code = :code)) AND entity.source = :source AND entity.isArchived = 0 ORDER BY entity.id DESC ``` Produced SQL on count query from Paginator: ```sql SELECT DISTINCT s0_.id AS id_0, s0_.id AS id_1 FROM my_entity s0_ WHERE s0_.id IN ( (SELECT s1_.id FROM my_entity s1_ INNER JOIN identifier_uses s2_ ON s1_.id = s2_.entity_id INNER JOIN identifiers s3_ ON s2_.identifier_id = s3_.id AND (s3_.deleted_at IS NULL) WHERE s3_.code = ?) ) AND s0_.source = ? AND s0_.is_archived = 0 ORDER BY s0_.id DESC LIMIT 20 ``` Later produces incorrect ids, as only 1 id is expected, but 2 are returned, even though the subquery by itself is correct, I believe the error is caused by multiple columns being present in select for this query, while paginator only expects one. It seems like it's caused by `LimitSubqueryWalker` adding a second select statement (at least from what I checked) #### Current behavior Incorrect IDs are returned by `Paginator` (variable: `$foundIdRows` in `getIterator`) #### Expected behavior Correct IDs are returned. #### How to reproduce I'll try to provide a repository with example data and entities shortly if needed.
admin closed this issue 2026-01-22 15:53:32 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7566