maxtepkeev / django-db-parti

[DEPRECATED] Django DB Parti - fully automatic database table partitioning for Django
BSD 3-Clause "New" or "Revised" License
31 stars 9 forks source link

Separate exception for (currently) unsupported auto_now_add datetime fields #2

Closed kmitrovic closed 10 years ago

kmitrovic commented 10 years ago

Check:

return getattr(self, '_get_{}_period'.format(self.period))()

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.

kmitrovic commented 10 years ago

Not good.

Not sure how this will work with field that has NULL value for real.

Will do a new implementation soon.