octobercms/october · error · SystemException

The aggregate function cannot be empty.

Error message

The aggregate function cannot be empty.

What it means

ReportMetric's constructor rejects an empty $aggregateFunction string with SystemException. The aggregate function decides how the metric is computed in SQL (sum/avg/min/max/count/none/count_distinct/count_distinct_not_null) and is later matched against a whitelist, so an empty value has no meaning. This guard fires before the whitelist check, catching the case where the argument was simply not provided. Use the AGGREGATE_* constants rather than raw strings.

Source

Thrown at modules/dashboard/classes/ReportMetric.php:78

    {
        if (!strlen($code)) {
            throw new SystemException('The metric code cannot be empty.');
        }

        if (!preg_match('/^[a-z][a-z0-9_]+$/i', $code)) {
            throw new SystemException('The metric code can only contain Latin letters, numbers and underscore. The first character must be a letter');
        }

        if (!strlen($databaseColumnName)) {
            throw new SystemException('The database column name cannot be empty.');
        }

        if (!strlen($displayName)) {
            throw new SystemException('The display name cannot be empty.');
        }

        if (!strlen($aggregateFunction)) {
            throw new SystemException('The aggregate function cannot be empty.');
        }

        $knownAggregateFunctions = [
            self::AGGREGATE_SUM,
            self::AGGREGATE_AVG,
            self::AGGREGATE_MIN,
            self::AGGREGATE_MAX,
            self::AGGREGATE_COUNT,
            self::AGGREGATE_NONE,
            self::AGGREGATE_COUNT_DISTINCT,
            self::AGGREGATE_COUNT_DISTINCT_NOT_NULL
        ];

        if (!in_array($aggregateFunction, $knownAggregateFunctions)) {
            throw new SystemException('The aggregate function is not supported: ' . $aggregateFunction);
        }

        $this->code = $code;

View on GitHub (pinned to b608633a7e)

Solutions

  1. Pass one of the ReportMetric::AGGREGATE_* constants as the 4th argument, e.g. ReportMetric::AGGREGATE_SUM.
  2. Default the config key sensibly: $fn = $cfg['aggregate'] ?? ReportMetric::AGGREGATE_COUNT; before constructing.
  3. For raw precomputed values, use AGGREGATE_NONE instead of an empty string.
  4. Re-run after the fix; the follow-up whitelist error ('The aggregate function is not supported') confirms you are now passing a non-empty but unrecognized value.

Example fix

// before
new ReportMetric('revenue', 'amount', 'Revenue', '');

// after
new ReportMetric('revenue', 'amount', 'Revenue', ReportMetric::AGGREGATE_SUM);
Defensive patterns

Strategy: validation

Validate before calling

$allowed = [
    ReportMetric::AGGREGATE_SUM, ReportMetric::AGGREGATE_AVG,
    ReportMetric::AGGREGATE_MIN, ReportMetric::AGGREGATE_MAX,
    ReportMetric::AGGREGATE_COUNT, ReportMetric::AGGREGATE_NONE,
    ReportMetric::AGGREGATE_COUNT_DISTINCT, ReportMetric::AGGREGATE_COUNT_DISTINCT_NOT_NULL,
];
$fn = $config['aggregate'] ?? ReportMetric::AGGREGATE_COUNT;
if (!in_array($fn, $allowed, true)) {
    throw new InvalidArgumentException("Unsupported aggregate: {$fn}");
}
$metric = new ReportMetric($code, $column, $label, $fn);

Prevention

When it happens

Trigger: Calling `new ReportMetric('code', 'col', 'Label', '')` — most often the 4th argument is omitted in a variadic/array-driven construction, or a config read like $cfg['aggregate'] ?? '' yields '' instead of a valid constant.

Common situations: Config-driven metric definitions missing the 'aggregate' key; developers assuming count is the default; passing null (typed string coerces or errors) or an uninitialized variable.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/f428e9c081820a24. Report an issue: GitHub.