The 1900 Leap Year Lie — Python Bug Hunt
Inspired by the most famous deliberate bug in software: spreadsheets treat 1900 as a leap year (inherited from Lotus 1-2-3 and kept by Excel for…
- Language: Python
- Layer: Backend
- Difficulty: Easy
- Concepts: Dates, Leap Years
- Modelled on: Excel / Lotus 1-2-3
- Visible tests: 1900 was not a leap year; 2000 was a leap year; ordinary leap years still work
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-3
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- 1900 was not a leap year — century rule: expected a truthy value but got false
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the most famous deliberate bug in software: spreadsheets treat 1900 as a leap year (inherited from Lotus 1-2-3 and kept by Excel for compatibility). Your date library copied the naive rule.
calendar_rules.py — the Gregorian rule has three clauses, not one.
Bug report
BUG-FEB29-1900 · Reported by: reporting pipeline
is_leap(year): divisible by 4, EXCEPT centuries, UNLESS divisible by 400.
- 1900 -> False (a century, not divisible by 400)
- 2000 -> True
- 1996 -> True
Observed: every date after 1900-02-28 in imported sheets is shifted one day.
Logs
[import] serial 60 -> 1900-02-29 (a date that never existed)The code as shipped
src/dates/calendar_rules.py (editable)
# Gregorian leap-year rule.
def is_leap(year):
return year % 4 == 0
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.