throws AttributeError in case datetime field has auto_now_add set to True.
This happens because the value for the field is initially (and at that point in time) None, and so further usage of self.now (self.now.year usage later on) raising the same (AttributeError) exception as if the set period is not within supported period.
So in this case the resulting exception said to me something like: "'week' is not in the supported periods: 'day', 'week', 'month', 'year'", which confused me until I saw the code.
Now, in the except branch on the line above, the self.now is None check is done first, and new type of exception is raised in that case.
If that is not the case, and if set period is not in the supported periods list, the old except block is executed (raising the old exception type).
In all other cases, the original AttributeError exception is re-raised.
Check:
throws AttributeError in case datetime field has auto_now_add set to True.
This happens because the value for the field is initially (and at that point in time) None, and so further usage of self.now (self.now.year usage later on) raising the same (AttributeError) exception as if the set period is not within supported period. So in this case the resulting exception said to me something like: "'week' is not in the supported periods: 'day', 'week', 'month', 'year'", which confused me until I saw the code.
Now, in the except branch on the line above, the self.now is None check is done first, and new type of exception is raised in that case. If that is not the case, and if set period is not in the supported periods list, the old except block is executed (raising the old exception type). In all other cases, the original AttributeError exception is re-raised.