mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.7.x] Fixed #23420 - broken warning for unbound naive datetime objects
Fixed issue with warning message displayed for unbound naive datetime
objects when USE_TZ is True. Adds unit test that demonstrates the issue
(discoverable when using a custom lookup in MySQL).
Backport of ceb1ffcc8d from master.
Conflicts:
	tests/custom_lookups/tests.py
			
			
This commit is contained in:
		
				
					committed by
					
						 Anssi Kääriäinen
						Anssi Kääriäinen
					
				
			
			
				
	
			
			
			
						parent
						
							74d0311d6b
						
					
				
				
					commit
					12e5b87b89
				
			| @@ -1272,9 +1272,13 @@ class DateTimeField(DateField): | ||||
|             # For backwards compatibility, interpret naive datetimes in local | ||||
|             # time. This won't work during DST change, but we can't do much | ||||
|             # about it, so we let the exceptions percolate up the call stack. | ||||
|             warnings.warn("DateTimeField %s.%s received a naive datetime (%s)" | ||||
|             try: | ||||
|                 name = '%s.%s' % (self.model.__name__, self.name) | ||||
|             except AttributeError: | ||||
|                 name = '(unbound)' | ||||
|             warnings.warn("DateTimeField %s received a naive datetime (%s)" | ||||
|                           " while time zone support is active." % | ||||
|                           (self.model.__name__, self.name, value), | ||||
|                           (name, value), | ||||
|                           RuntimeWarning) | ||||
|             default_timezone = timezone.get_default_timezone() | ||||
|             value = timezone.make_aware(value, default_timezone) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user