{"record":{"id":"bb743ae6354f8fdb","repo":"octobercms/october","slug":"cannot-use-both-limit-and-pagination","errorCode":null,"errorMessage":"Cannot use both limit and pagination.","messagePattern":"Cannot use both limit and pagination\\.","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/dashboard/classes/ReportQueryBuilder.php","lineNumber":677,"sourceCode":"    {\n        if (!$this->tableName) {\n            throw new SystemException('Table name is required.');\n        }\n\n        if (!$this->dimension) {\n            throw new SystemException('Dimension is required.');\n        }\n\n        if (($this->dateStart || $this->dateEnd) && $this->startTimestamp !== null) {\n            throw new SystemException('Cannot use both date range and timestamp filtering.');\n        }\n\n        if (!$this->dateStart && $this->startTimestamp === null) {\n            throw new SystemException('Either date range or start timestamp is required.');\n        }\n\n        if ($this->limit !== null && $this->pagination !== null) {\n            throw new SystemException('Cannot use both limit and pagination.');\n        }\n    }\n\n    /**\n     * buildQuery constructs the query builder\n     *\n     * @param bool $skipGrouping\n     * @param bool $skipPagination\n     * @param array $forceMetrics\n     * @return QueryBuilder\n     */\n    protected function buildQuery(\n        bool $skipGrouping = false,\n        bool $skipPagination = false,\n        array $forceMetrics = []\n    ): QueryBuilder {\n        $query = Db::table($this->tableName);\n","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/dashboard/classes/ReportQueryBuilder.php#L659-L695","documentation":"ReportQueryBuilder::validate() rejects having both $limit and $pagination set, throwing SystemException('Cannot use both limit and pagination.'). limit caps the row count (TOP N) while pagination implies paged result sets with page/pageSize semantics; combining them would make the resulting SQL ambiguous (limit inside or outside the page window). Set exactly one of the two before the builder validates.","triggerScenarios":"Calling both $builder->setLimit(10) and $builder->setPagination(...) (or the fluent limit()/paginate() equivalents) on the same builder; a widget config merge that retains a saved 'limit' while the request adds pagination params (e.g. ?page=2&per_page=20).","commonSituations":"Upgrading a widget from fixed Top-N output to a paginated table while the stored widget properties still contain the old limit value; copy-pasting builder setup between widgets; front-end sending both pageSize and limit keys.","solutions":["Keep one mechanism: for a fixed Top N use setLimit($n) and remove pagination setup; for paged output use setPagination($page, $perPage) and remove the limit.","When loading saved widget properties, unset 'limit' whenever pagination params are present (or vice versa) before configuring the builder.","Sanitize request input: accept either per_page/page or limit, never merge both into the builder.","Reset builder state if the same instance is reused for different widgets."],"exampleFix":"// before\n$builder->setLimit(10)->setPagination(2, 20);\n\n// after (Top N)\n$builder->setLimit(10);\n// or (paged)\n// $builder->setPagination(2, 20);","handlingStrategy":"validation","validationCode":"$props = $widget->properties;\nif (!empty($props['use_pagination'])) {\n    unset($props['limit']);\n    $builder->setPagination($page, $perPage);\n} else {\n    unset($props['page'], $props['per_page']);\n    $builder->setLimit((int) ($props['limit'] ?? 10));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide Top-N vs pagination per widget and strip the other option from merged properties.","When migrating a widget from limit to pagination, clear stored 'limit' properties for existing users.","Send either page/per_page or limit from the front-end, never both."],"tags":["dashboard","report-query-builder","pagination","conflicting-options"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}