Skip to content

Scheduled task cleanup_invalid_scheduled_mails fails with database JSON error #1474

Description

@c-roos268

Hi team,

We encountered a fatal database error when running the scheduled task for cleaning up invalid scheduled emails (mod_booking\task\cleanup_invalid_scheduled_mails).

Environment details:

Moodle version: 4.5.10 (Build: 20260216)

mod_booking version: 2026051900

Error message:

Plaintext
Error reading from database (Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.)

Cause:
The task uses the MySQL/MariaDB JSON_EXTRACT() function on a database column (likely within the booking tables). However, if a row contains an empty string ("" or NULL) instead of a valid JSON object ({}), the database query crashes instantly and causes the scheduled task to fail.

Suggested fix:
It would be great if the query within this task could be updated to safeguard against empty or null values. For example, by adding a condition to filter out empty rows before attempting to parse them with JSON_EXTRACT(), such as:

SQL
WHERE your_json_column IS NOT NULL AND your_json_column != '' AND your_json_column != '{}'

Could you please look into adding a fallback or validation check for empty data fields in this task so it doesn't break the cron execution?

Thank you!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions