Ticket #17294: 17294.patch

File 17294.patch, 2.4 KB (added by Aymeric Augustin, 13 years ago)
  • tests/modeltests/timezones/tests.py

     
    2525from django.utils.unittest import skipIf
    2626
    2727from .forms import EventForm, EventSplitForm, EventModelForm
    28 from .models import Event, Timestamp
     28from .models import Event, MaybeEvent, Timestamp
    2929
    3030
    3131# These tests use the EAT (Eastern Africa Time) and ICT (Indochina Time)
     
    403403                 datetime.datetime(2011, 1, 1, tzinfo=UTC)],
    404404                transform=lambda d: d)
    405405
     406    def test_null_datetime(self):
     407        # Regression for #17294
     408        e = MaybeEvent.objects.create()
     409        self.assertEqual(e.dt, None)
     410
    406411NewDatabaseTests = override_settings(USE_TZ=True)(NewDatabaseTests)
    407412
    408413
  • tests/modeltests/timezones/models.py

     
    33class Event(models.Model):
    44    dt = models.DateTimeField()
    55
     6class MaybeEvent(models.Model):
     7    dt = models.DateTimeField(blank=True, null=True)
     8
    69class Timestamp(models.Model):
    710    created = models.DateTimeField(auto_now_add=True)
    811    updated = models.DateTimeField(auto_now=True)
  • tests/modeltests/timezones/forms.py

     
    11from django import forms
    22
    3 from .models import Event
     3from .models import Event, MaybeEvent
    44
    55class EventForm(forms.Form):
    66    dt = forms.DateTimeField()
  • django/db/models/fields/__init__.py

     
    786786
    787787    def get_prep_value(self, value):
    788788        value = self.to_python(value)
    789         if settings.USE_TZ and timezone.is_naive(value):
     789        if value is not None and settings.USE_TZ and timezone.is_naive(value):
    790790            # For backwards compatibility, interpret naive datetimes in local
    791791            # time. This won't work during DST change, but we can't do much
    792792            # about it, so we let the exceptions percolate up the call stack.
Back to Top