moodle/moodle · error · moodle_exception
mustbeoveride
mustbeoveride
Error message
mustbeoveride
What it means
This is a Moodle abstract-base-class guard. filter_object (public/user/filters/lib.php) declares get_sql_filter() as a method every concrete filter type must override; the base implementation does nothing but throw \moodle_exception('mustbeoveride','debug','','get_sql_filter'). It fires when code calls get_sql_filter() on a filter subclass that never implemented it, i.e. an unimplemented abstract method, not a runtime data problem.
Solutions
- Implement get_sql_filter($data) in the concrete filter subclass, returning the SQL WHERE condition string (or null if the filter is disabled).
- Check that you are instantiating the intended concrete filter subclass, not the abstract base class from lib.php.
- Compare your subclass against a core filter (e.g. user/filters/text.php or checkbox.php) and implement every method the base class marks as must-be-overridden.
- If the exception names 'get_sql_filter' but you did override it, verify there is no signature/visibility mismatch (e.g. protected vs public, wrong parameter list) that silently skips the override.
Example fix
// before
class my_custom_filter extends filter_type {
public function setupForm(&$mform) { /* ... */ }
// get_sql_filter() never implemented -> base class throws mustbeoveride
}
// after
class my_custom_filter extends filter_type {
public function setupForm(&$mform) { /* ... */ }
public function get_sql_filter($data) {
if (empty($data['value'])) {
return null; // filter disabled
}
return 'fieldname = ' . $data['value'];
}
} Defensive patterns
Strategy: type-guard
Validate before calling
// Before using a filter instance, ensure all required overrides exist:
if (!method_exists($filter, 'get_sql_filter')) {
throw new coding_exception('Filter class ' . get_class($filter) . ' must override get_sql_filter()');
} Type guard
// PHP guard for a properly implemented filter subclass
function is_implemented_filter($filter): bool {
return $filter instanceof filter_type
&& (new ReflectionMethod($filter, 'get_sql_filter'))->getDeclaringClass()->getName() !== 'filter_type';
} Try / catch
try {
$condition = $filter->get_sql_filter($data);
} catch (\moodle_exception $e) {
if ($e->errorcode === 'mustbeoveride') {
debugging('Filter subclass missing get_sql_filter override: ' . get_class($filter), DEBUG_DEVELOPER);
$condition = null; // treat filter as disabled
} else {
throw $e;
}
} Prevention
- Always implement all four mandatory methods (get_sql_filter, check_data, setupForm, get_label) when creating a filter subclass.
- Derive new filters from a core concrete filter or copy its full method set.
- Add a unit test that instantiates each filter subclass and asserts none of the base methods throw mustbeoveride.
- Run Reflection checks in dev to catch base-class-only implementations early.
When it happens
Trigger: Calling get_sql_filter($data) on an instance of a class extending the base filter class in user/filters/lib.php that has not overridden get_sql_filter() — typically a custom or third-party user filter with an incomplete implementation, or the base class instantiated directly.
Common situations: Writing a new custom user filter and forgetting to implement get_sql_filter() while implementing the other required methods; upgrading Moodle so a previously working subclass no longer matches the API contract; instantiating the abstract base filter_type directly instead of a concrete subclass.
Understand the failure class
Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.
Related errors
- Invalid direction specified
- Invalid join type specified
- Some filter types are both required, and optional:
- The filter class ' ' for filter ' ' could not be found.
- The filter specified
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/6355fcf2ae1de804.
Report an issue: GitHub.
Appendix: source
Thrown at public/user/filters/lib.php:323
/**
* Constructor
* @param string $name the name of the filter instance
* @param string $label the label of the filter instance
* @param boolean $advanced advanced form element flag
*/
public function __construct($name, $label, $advanced) {
$this->_name = $name;
$this->_label = $label;
$this->_advanced = $advanced;
}
/**
* Returns the condition to be used with SQL where
* @param array $data filter settings
* @return string the filtering condition or null if the filter is disabled
*/
public function get_sql_filter($data) {
throw new \moodle_exception('mustbeoveride', 'debug', '', 'get_sql_filter');
}
/**
* Retrieves data from the form data
* @param stdClass $formdata data submited with the form
* @return mixed array filter data or false when filter not set
*/
public function check_data($formdata) {
throw new \moodle_exception('mustbeoveride', 'debug', '', 'check_data');
}
/**
* Adds controls specific to this filter in the form.
* @param moodleform $mform a MoodleForm object to setup
*/
public function setupForm(&$mform) {
throw new \moodle_exception('mustbeoveride', 'debug', '', 'setupForm');
}View on GitHub (pinned to 48ea8c3322)