octobercms/october · error · Error
Cannot switch to container: a container element is not found
Error message
Cannot switch to container: a container element is not found
What it means
ReportDataPaginationParams is the value object dashboard report widgets use to paginate result sets. Its constructor enforces that `$recordsPerPage` is a positive integer (> 0) — zero or negative values are rejected immediately with this ApplicationException, since they make page math (offset = page * recordsPerPage) meaningless or division-based calculations fatal.
Source
Thrown at modules/backend/assets/foundation/controls/inspector/inspector.manager.js:85
var options = $.extend(this.loadElementOptions(wrapper.$element), {
containerSupported: true
})
new $.oc.inspector.wrappers.popup(wrapper.$element, wrapper, options)
wrapper.cleanupAfterSwitch();
this.setContainerPreference(false);
}
InspectorManager.prototype.switchToContainer = function(wrapper) {
var $container = this.getContainerElement(wrapper.$element),
options = $.extend(this.loadElementOptions(wrapper.$element), {
containerSupported: true,
container: $container
});
if (!$container) {
throw new Error('Cannot switch to container: a container element is not found');
}
new $.oc.inspector.wrappers.container(wrapper.$element, wrapper, options);
wrapper.cleanupAfterSwitch();
this.setContainerPreference(true);
}
InspectorManager.prototype.createInspector = function(element) {
var $element = $(element);
if ($element.data('oc.inspectorVisible')) {
return false;
}
var $container = this.getContainerElement($element);
// If there's no container option, create the Inspector popupView on GitHub (pinned to b608633a7e)
Solutions
- Pass a positive page size, e.g. `new ReportDataPaginationParams(20, $page)`.
- Guard user input before constructing: reject or default `per_page` values below 1 in the handler.
- If 'no pagination' is needed, skip creating ReportDataPaginationParams entirely rather than passing 0.
Example fix
// before
new ReportDataPaginationParams((int) array_get($params, 'per_page', 0), 0);
// after
$perPage = (int) array_get($params, 'per_page', 20);
if ($perPage < 1) {
$perPage = 20;
}
new ReportDataPaginationParams($perPage, 0); Defensive patterns
Strategy: validation
Validate before calling
// Validate at the request boundary
$perPage = (int) request()->input('per_page', 20);
if ($perPage < 1) {
throw new ValidationException(['per_page' => 'Records per page must be a positive integer']);
}
$params = new \Dashboard\Classes\ReportDataPaginationParams($perPage, max(0, $page)); Type guard
/**
* @param mixed $value
* @returns {boolean}
*/
function isPositivePageCount($value)
{
return is_int($value) && $value > 0;
} Prevention
- Default page size to a sane positive constant (e.g. 20) instead of 0 when input is missing.
- Validate per_page/limit query parameters as integers >= 1 before building pagination.
- Skip pagination entirely rather than passing 0 to mean 'all records'.
When it happens
Trigger: Constructing with `(int) get('per_page')` when the parameter is absent so it casts to 0; a UI page-size selector that allows 0 or empty; defaulting recordsPerPage to 0 in a custom report widget before the user picks a size.
Common situations: Optional 'limit'/'per_page' request parameters that arrive empty and become 0; widgets initialized before configuration loads; tests constructing the object with 0 to mean 'no pagination'.
Related errors
- Inspector surface unique ID should be defined.
- Cannot find the requested row group.
- Inspector container ${$containerHolder.data['inspector-conta
- Trying to get selected row without a popup reference.
- Key property ${keyProperty} is not found in the Inspector da
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/36f0e11612fdceed.
Report an issue: GitHub.