mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[1.11.x] Fixed #28230 -- Allowed DjangoJsonEncoder to serialize CallableBool.
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							65dfe579d0
						
					
				
				
					commit
					d1d08d86ba
				
			| @@ -16,6 +16,7 @@ from django.core.serializers.python import ( | |||||||
|     Deserializer as PythonDeserializer, Serializer as PythonSerializer, |     Deserializer as PythonDeserializer, Serializer as PythonSerializer, | ||||||
| ) | ) | ||||||
| from django.utils import six | from django.utils import six | ||||||
|  | from django.utils.deprecation import CallableBool | ||||||
| from django.utils.duration import duration_iso_string | from django.utils.duration import duration_iso_string | ||||||
| from django.utils.functional import Promise | from django.utils.functional import Promise | ||||||
| from django.utils.timezone import is_aware | from django.utils.timezone import is_aware | ||||||
| @@ -117,5 +118,7 @@ class DjangoJSONEncoder(json.JSONEncoder): | |||||||
|             return str(o) |             return str(o) | ||||||
|         elif isinstance(o, Promise): |         elif isinstance(o, Promise): | ||||||
|             return six.text_type(o) |             return six.text_type(o) | ||||||
|  |         elif isinstance(o, CallableBool): | ||||||
|  |             return bool(o) | ||||||
|         else: |         else: | ||||||
|             return super(DjangoJSONEncoder, self).default(o) |             return super(DjangoJSONEncoder, self).default(o) | ||||||
|   | |||||||
| @@ -29,3 +29,6 @@ Bugfixes | |||||||
| * Fixed a regression where ``Model._state.adding`` wasn't set correctly on | * Fixed a regression where ``Model._state.adding`` wasn't set correctly on | ||||||
|   multi-table inheritance parent models after saving a child model |   multi-table inheritance parent models after saving a child model | ||||||
|   (:ticket:`28210`). |   (:ticket:`28210`). | ||||||
|  |  | ||||||
|  | * Allowed ``DjangoJSONEncoder`` to serialize | ||||||
|  |   ``django.utils.deprecation.CallableBool`` (:ticket:`28230`). | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ from django.core.serializers.json import DjangoJSONEncoder | |||||||
| from django.db import models | from django.db import models | ||||||
| from django.test import SimpleTestCase, TestCase, TransactionTestCase | from django.test import SimpleTestCase, TestCase, TransactionTestCase | ||||||
| from django.test.utils import isolate_apps | from django.test.utils import isolate_apps | ||||||
|  | from django.utils.deprecation import CallableFalse, CallableTrue | ||||||
| from django.utils.translation import override, ugettext_lazy | from django.utils.translation import override, ugettext_lazy | ||||||
|  |  | ||||||
| from .models import Score | from .models import Score | ||||||
| @@ -315,3 +316,7 @@ class DjangoJSONEncoderTests(SimpleTestCase): | |||||||
|             json.dumps({'duration': duration}, cls=DjangoJSONEncoder), |             json.dumps({'duration': duration}, cls=DjangoJSONEncoder), | ||||||
|             '{"duration": "P0DT00H00M00S"}' |             '{"duration": "P0DT00H00M00S"}' | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |     def test_callable_bool(self): | ||||||
|  |         self.assertEqual(json.dumps(CallableTrue, cls=DjangoJSONEncoder), 'true') | ||||||
|  |         self.assertEqual(json.dumps(CallableFalse, cls=DjangoJSONEncoder), 'false') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user