Critical scheduler bugs require deep understanding of timezone handling and NULL value logic.
Two critical scheduler bugs cause complete failure: NULL trap prevents scheduler from starting on fresh sites, and timezone mismatches write future timestamps. Both issues require careful handling of NULL values and timezone logic in core scheduler functionality.
Summary
Two critical scheduler bugs that break ERPNext on fresh installations and deployments with timezone mismatches:
Both result in complete scheduler failure with zero error messages or warnings.
Severity: Critical - Breaks core functionality silently
Affected Versions: Frappe v15.99.0, v16.5.0 + ERPNext v15.96.1, v16.4.1 (likely all versions)
Impact: Email queue, backups, scheduled reports, all background jobs stop working
ISSUE ONE: NULL Trap on Fresh Site Creation
The Problem
Every new site created with bench new-site ends up with a broken scheduler from day one. In Scheduled Job Type, the last_execution field is either NULL or sometimes gets written as a future timestamp. Even though is_event_due() should treat NULL as due, in practice jobs are never enqueued, and last_execution stays stuck (or remains incorrectly in the future), so nothing runs automatically.
Reproduction Steps
Query:
SELECT method, last_execution, stopped
FROM `tabScheduled Job Type`
WHERE method='frappe.email.queue.flush';
Result: last_execution remains NULL forever (see screenshot 1)
Impact
Root Cause
The enqueue() method in scheduled_job_type.py silently returns False for NULL values despite is_event_due() returning True. The scheduler loop calls enqueue_events() which never actually enqueues anything.
Evidence:
# Console test showing the bug
do
Claim this issue to let others know you're working on it. You'll earn 30 points when you complete it!