Review main Merged

86378[BUGFIX] Mitigate invalid `count` query in `PageInformationController`

Stefan Bürk CR +2 V +2 Hard +336 −1 updated 10/10/24, 18:58

Commit message

Database systems like postgresql require to have all `ORDER BY` or
`GROUP BY` columns also specified in `SELECT` specifier list.

That means: Whenever a database query is composed using the
`QueryBuilder` API to create a basic `SELECT` query with corresponding
ordering or grouping definitions, a derived count query needs to take
extra care to properly remove ordering and grouping definitions.
Actually they do not make any sense in count queries anyway, so removing
them does not harm anyway.

This change clones the created `QueryBuilder` before executing the
select query and removes ordering definitions before reusing it to
initiate a count operation.

The query is now covered with a functional test, currently testing the
controller. That is mainly done to preserve easier backporting of this
bugfix and extract database query or buildup into a dedicated testable
service later.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Benjamin Franzke +1
    • Garvin Hicking +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Benjamin Franzke +1
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 5

Review log 1518

  1. Stefan Bürk uploaded patch set 1 09/29/24, 21:07

  2. core-ci voted on patch set 1 V +1 09/29/24, 21:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66816

  3. Garvin Hicking voted on patch set 1 CR +1 09/30/24, 05:05

  4. Thomas Hohn voted on patch set 1 CR +1 09/30/24, 05:06

  5. Nikita Hovratov commented on patch set 1 V +1 09/30/24, 06:52

    PageInformationControllerTest.php:325

    Maybe just use reflection here instead of extending the controller, like we did in previous patches? Providing the dependencies manually looks fragile.
  6. Stefan Bürk commented on patch set 1 09/30/24, 09:22

    PageInformationControllerTest.php:325 Reply

    Reflection is not needed here, like the exten more. In the end it should be extracted into a dedicated service to avoid extending/reflection at all. My reasoning for this approach was to have everything in place for changes, and changes in constructor DI needs to be adjusted in that test for example.
  7. Benjamin Franzke commented on patch set 1 09/30/24, 09:27

    PageInformationControllerTest.php:325 Reply

    I'd suggest following alternative via Closure::bind, so no need to fake an object at all, just fake the scope: ``` $pageInformationController = $this->get(PageInformationController::class); $getPageRecordsRecursive = \Closure::bind( static fn () => $pageInformationController->getPageRecordsRecursive(...func_get_args()), null, PageInformationController::class ); self::assertSame($expectedRows, $getPageRecordsRecursive($pid, $depth)); ```
  8. Benjamin Franzke uploaded patch set 2 CR +1 V +1 09/30/24, 09:41

  9. Benjamin Franzke commented on patch set 2 09/30/24, 09:41

    PageInformationControllerTest.php:325 Reply

    Done
  10. core-ci voted on patch set 2 V +1 09/30/24, 09:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66847

  11. Benjamin Franzke voted on patch set 2 V +1 09/30/24, 12:47

  12. Benjamin Franzke uploaded patch set 3 CR +1 V +1 09/30/24, 14:33

  13. Benjamin Franzke commented on patch set 3 09/30/24, 14:33

    PageInformationControllerTest.php:325 Reply

    talked to lolli and aligned to `\ReflectionMethod`, since we already use that in other tests.
  14. Benjamin Franzke voted on patch set 3 CR +1 V +1 09/30/24, 14:33

  15. core-ci voted on patch set 3 V +1 09/30/24, 14:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66857

  16. Garvin Hicking voted on patch set 3 CR +1 V +1 10/10/24, 17:39

  17. Stefan Bürk voted on patch set 3 CR +2 V +2 10/10/24, 18:58

  18. Stefan Bürk merged patch set 4 10/10/24, 18:58