I have two models, both of which have a date field defaulting to the current date, whatever that may be. Today someone pointed out they were getting an error from one of them, which was setting dates to 19 December instead of 23 December (today at the time of writing).
I had thought both fields were set up identically so I checked for an unintended difference between the two and found one. But I was surprised because the 'working' one was the one that looked to me like it contained an error. The fields are set up like this:
# Working field
date_stamp = models.DateField(default=datetime.date.today)
# Broken field
date_statp = models.DateField(default=datetime.date.today())
I always thought the today
function needed to be called to ensure the value wasn't cached. Is the reverse in fact true? Can someone explain how these two are actually interpreted on model instance creation?