mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[4.0.x] Fixed #33033 -- Prevented models.DecimalField from accepting NaN values.
Backport of b7fd668b37 from main
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							a9479202d7
						
					
				
				
					commit
					6f31041794
				
			| @@ -1,3 +1,4 @@ | ||||
| import math | ||||
| from decimal import Decimal | ||||
|  | ||||
| from django.core import validators | ||||
| @@ -65,6 +66,13 @@ class DecimalFieldTests(TestCase): | ||||
|         bd = BigD.objects.get(pk=bd.pk) | ||||
|         self.assertEqual(bd.d, Decimal('12.9')) | ||||
|  | ||||
|     def test_save_nan_invalid(self): | ||||
|         msg = '“nan” value must be a decimal number.' | ||||
|         with self.assertRaisesMessage(ValidationError, msg): | ||||
|             BigD.objects.create(d=float('nan')) | ||||
|         with self.assertRaisesMessage(ValidationError, msg): | ||||
|             BigD.objects.create(d=math.nan) | ||||
|  | ||||
|     def test_fetch_from_db_without_float_rounding(self): | ||||
|         big_decimal = BigD.objects.create(d=Decimal('.100000000000000000000000000005')) | ||||
|         big_decimal.refresh_from_db() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user