From a5de0df58b5431b25a3246a57432db73843be87f Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Tue, 6 May 2014 18:14:06 -0700 Subject: Fixed #22502 -- Fixed microseconds/default/form interaction Made explicit lack of microsecond handling by built-in datetime form fields. Used that explicitness to appropriately nix microsecond values in bound fields. Thanks Claude Paroz for the review. --- django/forms/forms.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'django/forms/forms.py') diff --git a/django/forms/forms.py b/django/forms/forms.py index 917987c0be..f248d08726 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals from collections import OrderedDict import copy +import datetime import warnings from django.core.exceptions import ValidationError, NON_FIELD_ERRORS @@ -593,6 +594,11 @@ class BoundField(object): data = self.form.initial.get(self.name, self.field.initial) if callable(data): data = data() + # If this is an auto-generated default date, nix the + # microseconds for standardized handling. See #22502. + if (isinstance(data, (datetime.datetime, datetime.time)) and + not getattr(self.field.widget, 'supports_microseconds', True)): + data = data.replace(microsecond=0) else: data = self.field.bound_data( self.data, self.form.initial.get(self.name, self.field.initial) -- cgit v1.3