@@ -1289,7 +1289,7 @@ def to_python(self, value):
1289
1289
if value is None :
1290
1290
return value
1291
1291
if isinstance (value , datetime .datetime ):
1292
- if settings . USE_TZ and timezone .is_aware (value ):
1292
+ if timezone .is_aware (value ):
1293
1293
# Convert aware datetimes to the default time zone
1294
1294
# before casting them to dates (#17742).
1295
1295
default_timezone = timezone .get_default_timezone ()
@@ -1391,20 +1391,21 @@ def to_python(self, value):
1391
1391
return value
1392
1392
if isinstance (value , datetime .date ):
1393
1393
value = datetime .datetime (value .year , value .month , value .day )
1394
- if settings .USE_TZ :
1395
- # For backwards compatibility, interpret naive datetimes in
1396
- # local time. This won't work during DST change, but we can't
1397
- # do much about it, so we let the exceptions percolate up the
1398
- # call stack.
1399
- warnings .warn (
1400
- "DateTimeField {}.{} received a naive datetime "
1401
- "({}) while time zone support is active." .format (
1402
- self .model .__name__ , self .name , value
1403
- ),
1404
- RuntimeWarning ,
1405
- )
1406
- default_timezone = timezone .get_default_timezone ()
1407
- value = timezone .make_aware (value , default_timezone )
1394
+
1395
+ # For backwards compatibility, interpret naive datetimes in
1396
+ # local time. This won't work during DST change, but we can't
1397
+ # do much about it, so we let the exceptions percolate up the
1398
+ # call stack.
1399
+ warnings .warn (
1400
+ "DateTimeField {}.{} received a naive datetime "
1401
+ "({}) while time zone support is active." .format (
1402
+ self .model .__name__ , self .name , value
1403
+ ),
1404
+ RuntimeWarning ,
1405
+ )
1406
+ default_timezone = timezone .get_default_timezone ()
1407
+ value = timezone .make_aware (value , default_timezone )
1408
+
1408
1409
return value
1409
1410
1410
1411
try :
@@ -1449,7 +1450,7 @@ def pre_save(self, model_instance, add):
1449
1450
def get_prep_value (self , value ):
1450
1451
value = super ().get_prep_value (value )
1451
1452
value = self .to_python (value )
1452
- if value is not None and settings . USE_TZ and timezone .is_naive (value ):
1453
+ if value is not None and timezone .is_naive (value ):
1453
1454
# For backwards compatibility, interpret naive datetimes in local
1454
1455
# time. This won't work during DST change, but we can't do much
1455
1456
# about it, so we let the exceptions percolate up the call stack.
0 commit comments