1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

[5.0.x] Fixed #34921 -- Fixed crash of warning for unbound naive datetimes.

Backport of b5311ee232 from main
This commit is contained in:
David Sanders
2023-10-22 18:41:30 +11:00
committed by Mariusz Felisiak
parent 4979e83d08
commit 4dec7eded9
2 changed files with 14 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ from django.contrib.auth.models import User
from django.core import serializers
from django.db import connection
from django.db.models import F, Max, Min
from django.db.models.functions import Now
from django.http import HttpRequest
from django.template import (
Context,
@@ -327,6 +328,13 @@ class NewDatabaseTests(TestCase):
event = Event.objects.get()
self.assertEqual(event.dt, datetime.datetime(2011, 9, 1, tzinfo=EAT))
@requires_tz_support
def test_filter_unbound_datetime_with_naive_date(self):
dt = datetime.date(2011, 9, 1)
msg = "DateTimeField (unbound) received a naive datetime"
with self.assertWarnsMessage(RuntimeWarning, msg):
Event.objects.annotate(unbound_datetime=Now()).filter(unbound_datetime=dt)
@requires_tz_support
def test_naive_datetime_with_microsecond(self):
dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060)