Issue Bug Closed

#101913SQLSTATE[42803]: Grouping error: 7 ERROR: column "sys_http_report.uuid" must appear in the GROUP BY clause or be used in an aggregate function

Kochin Chang 09/13/23, 13:31 updated 07/09/24, 15:19

Description

The administration log this error message after turning on the Content Security Policy:

Core: Exception handler (WEB): Uncaught TYPO3 Exception: #7: An exception occurred while executing a query: SQLSTATE[42803]: Grouping error: 7 ERROR: column "sys_http_report.uuid" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: ... * FROM "sys_http_report" WHERE "uuid" IN (SELECT "uuid" FRO... ^ | Doctrine\DBAL\Exception\DriverException thrown in file /var/www/TYPO3/vendor/doctrine/dbal/src/Driver/API/PostgreSQL/ExceptionConverter.php in line 87. Requested URL: http://cms/typo3/ajax/security/csp/control?token=--AnonymizedToken--    \

And the PostgreSQL log shows:

ERROR:  column "sys_http_report.uuid" must appear in the GROUP BY clause or be used in an aggregate function at character 57
STATEMENT:  SELECT * FROM "sys_http_report" WHERE "uuid" IN (SELECT "uuid" FROM "sys_http_report" WHERE ("type" = $1) AND ("status" = $2) GROUP BY "summary" ORDER BY "created" desc) ORDER BY "created" desc

The PHP code for this was found in the file vendor/typo3/cms-core/Classes/Security/ContentSecurityPolicy/Reporting/ReportRepository.php.

    /**
     * @return list<SummarizedReport>
     */
    public function findAllSummarized(ReportDemand $demand = null): array
    {
        $demand ??= ReportDemand::create();
        $queryBuilder = $this->prepareQueryBuilder($demand);
        $subQueryBuilder = $this->prepareQueryBuilder($demand, $queryBuilder)
            ->select('uuid')
            ->groupBy('summary');
        $result = $queryBuilder
            ->select('*')
            ->where($queryBuilder->expr()->in('uuid', $subQueryBuilder->getSQL()))
            ->executeQuery();

        $summaryCountMap = $this->fetchSummaryCountMap();

        return array_map(
            static fn (array $row) => SummarizedReport::fromArray($row)
                ->withCount($summaryCountMap[$row['summary']] ?? 0),
            $result->fetchAllAssociative()
        );
    }

Reviews 2