
I came across a classic bug this morning. Some data that was supposed to be saved in a cache for two months wasn’t there, and my colleague had hunted fruitlessly on Friday for the reason it had gone astray. I didn’t know the code involved so started working out what it did, whereupon I encountered this line:
Code:
cache_stuff(cache_timeout=60 * 60 * 24 * 20) # 2 months

And that was it! The problem is that a month is approximated as 30 days, so two months is 60 days, and when you look at this line, you see the “2 months” comment at the end and you see 60 appearing, not once but twice, in the calculation, and you think it seems OK and you go off and start looking at another place where you think the bug might be. I spotted that the 20 at the end was the culprit almost immediately, because I didn’t know the code so I had no idea of where else I might look

To add to the fun, this data is generated at the start of the month, so it might not even have been noticed that there was a problem if somebody hadn’t happened to be looking at it after the twentieth of November






. Remember the ep of Dad's Army they never showed again?
Leave a comment: