{"record":{"id":"09d5873e62500972","repo":"octobercms/october","slug":"date-dimensions-cannot-have-fields","errorCode":null,"errorMessage":"Date dimensions cannot have fields.","messagePattern":"Date dimensions cannot have fields\\.","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/dashboard/classes/ReportDimension.php","lineNumber":152,"sourceCode":"            throw new SystemException('Unknown dimension type: ' . $dimensionType);\n        }\n\n        $this->code = $code;\n        $this->databaseColumnName = $databaseColumnName;\n        $this->displayName = $displayName;\n        $this->dimensionType = $dimensionType;\n        $this->labelColumnName = $labelColumnName;\n    }\n\n    /**\n     * Adds a field to this dimension.\n     * @param ReportDimensionField $field Specifies the field to add.\n     * @return $this Returns the dimension object for method chaining.\n     */\n    public function addDimensionField(ReportDimensionField $field): ReportDimension\n    {\n        if ($this->isDate()) {\n            throw new SystemException('Date dimensions cannot have fields.');\n        }\n\n        $this->dimensionFields[] = $field;\n        return $this;\n    }\n\n    /**\n     * Allows setting of custom field names for building queries that group data by week, month, quarter, and year intervals.\n     * If the fields are not set, ReportDataQueryBuilder will use SQL functions to deduce interval start dates\n     * from the dimension column value. This approach is less efficient than using indexed columns.\n     * The names specified in the arguments must refer to columns containing start dates for the corresponding\n     * intervals in the YYYY-MM-DD format. For example, the year column should contain values like 2023-01-01, 2024-01-01, etc.\n     *\n     * @param string $weekField The name of the column containing week start dates.\n     * @param string $monthField The name of the column containing month start dates.\n     * @param string $quarterField The name of the column containing quarter start dates.\n     * @param string $yearField The name of the column containing year start dates.\n     */","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/dashboard/classes/ReportDimension.php#L134-L170","documentation":"Date dimensions (code exactly 'date', ReportDimension::CODE_DATE) are grouped by week/month/quarter/year directly from the dimension column by ReportDataQueryBuilder, so they cannot carry dimension fields. addDimensionField() checks isDate() and throws whenever a field is added to such a dimension.","triggerScenarios":"$dateDimension = new ReportDimension(ReportDimension::CODE_DATE, 'created_at', 'Date'); $dateDimension->addDimensionField(new ReportDimensionField('oc_field_status', 'Status')); — any addDimensionField() call on a dimension whose code === 'date'.","commonSituations":"Generic registration loops that iterate a config array and call addDimensionField() on every dimension, including the built-in 'date' dimension; reusing one field-registration routine for heterogeneous dimension lists.","solutions":["Skip field registration for date dimensions: wrap addDimensionField() in if (!$dimension->isDate()) {...}","If you truly need selectable sub-attributes, use a regular dimension code other than 'date' (e.g. 'status') and add fields to it instead","Ensure config-driven dimension definitions do not include a 'fields' key for the 'date' dimension"],"exampleFix":"// before\nforeach ($fields as $field) {\n    $dateDimension->addDimensionField($field);\n}\n\n// after\nforeach ($fields as $field) {\n    if (!$dateDimension->isDate()) {\n        $dateDimension->addDimensionField($field);\n    }\n}","handlingStrategy":"type-guard","validationCode":"if ($dimension->getCode() === ReportDimension::CODE_DATE) {\n    // date dimension: skip addDimensionField entirely\n    return;\n}\n$dimension->addDimensionField($field);","typeGuard":"function dimensionSupportsFields(ReportDimension $dimension): bool\n{\n    return !$dimension->isDate();\n}","tryCatchPattern":null,"preventionTips":["Never call addDimensionField() on the built-in 'date' dimension (code === 'date')","In config-driven registration loops, add a 'fields' key only to non-date dimensions","Unit-test dimension setup routines with a date dimension included"],"tags":["php","dashboard","report","dimension","date"],"backgroundTag":"invalid-object-state","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}