octobercms/october · error · ApplicationException

Metric not found: $metricCode

Error message

Metric not found: $metricCode

What it means

ApplicationException thrown while ReportDataQueryBuilder::getMetricTotals is assembling totals: it looks up each metric configuration by code in the query builder's internal metric set and the given $metricCode has no matching registered metric. It fires when the report's metric configuration references a metric code that the data source / builder does not define (or it was renamed/removed).

Solutions

  1. Correct the metric code in the report configuration so it matches a metric actually registered by the data source
  2. Register the missing metric code on the data source / query builder side
  3. Clear cached report configurations after renaming a metric code
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/dashboard/classes/ReportDataQueryBuilder.php:326 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at modules/dashboard/classes/ReportDataQueryBuilder.php:326

        return $wrappedQuery->count();
    }

    /**
     * getMetricTotals returns totals for metric with the metric totals or the relative bar enabled.
     * @param ReportMetricConfiguration[] $metricsConfiguration
     * @return array Returns an array of metric total values
     */
    public function getMetricTotals(array $metricsConfiguration): array
    {
        // Totals use the same query as for dimensions but without grouping or pagination.

        $metrics = [];
        foreach ($metricsConfiguration as $metricCode => $configuration) {
            if ($configuration->getDisplayTotals() || $configuration->getDisplayRelativeBar()) {
                $metric = ReportMetric::findMetricByCode($this->metrics, $metricCode);
                if (!$metric) {
                    throw new ApplicationException("Metric not found: $metricCode");
                }

                $metrics[] = $metric;
            }
        }

        if (!count($metrics)) {
            return [];
        }

        $query = $this->createQueryBuilder(true, $metrics);
        $rows = $query->get()->toArray();
        if (!count($rows)) {
            return [];
        }

        $row = $rows[0];
        $result = [];

View on GitHub (pinned to b608633a7e)