mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #23770 -- Changed serialization strategy for floats with respect to NaN and Inf
Thanks to w0rp for the report
This commit is contained in:
parent
b07aa52e8a
commit
c7c098cf97
@ -1,10 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import inspect
|
||||
import decimal
|
||||
import collections
|
||||
import datetime
|
||||
import decimal
|
||||
from importlib import import_module
|
||||
import inspect
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@ -304,7 +305,11 @@ class MigrationWriter(object):
|
||||
elif isinstance(value, SettingsReference):
|
||||
return "settings.%s" % value.setting_name, {"from django.conf import settings"}
|
||||
# Simple types
|
||||
elif isinstance(value, six.integer_types + (float, bool, type(None))):
|
||||
elif isinstance(value, float):
|
||||
if math.isnan(value) or math.isinf(value):
|
||||
return 'float("{}")'.format(value), set()
|
||||
return repr(value), set()
|
||||
elif isinstance(value, six.integer_types + (bool, type(None))):
|
||||
return repr(value), set()
|
||||
elif isinstance(value, six.binary_type):
|
||||
value_repr = repr(value)
|
||||
|
@ -49,3 +49,6 @@ Bugfixes
|
||||
|
||||
* Allowed usage of ``DateTimeField()`` as ``Transform.output_field``
|
||||
(:ticket:`23420`).
|
||||
|
||||
* Fixed a migration serializing bug involving ``float("nan")`` and
|
||||
``float("inf")`` (:ticket:23770:).
|
||||
|
@ -2,6 +2,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import tokenize
|
||||
@ -69,6 +70,10 @@ class WriterTests(TestCase):
|
||||
"""
|
||||
# Basic values
|
||||
self.assertSerializedEqual(1)
|
||||
self.assertSerializedEqual(1.2)
|
||||
self.assertTrue(math.isinf(self.serialize_round_trip(float("inf"))))
|
||||
self.assertTrue(math.isinf(self.serialize_round_trip(float("-inf"))))
|
||||
self.assertTrue(math.isnan(self.serialize_round_trip(float("nan"))))
|
||||
self.assertSerializedEqual(None)
|
||||
self.assertSerializedEqual(b"foobar")
|
||||
string, imports = MigrationWriter.serialize(b"foobar")
|
||||
|
Loading…
Reference in New Issue
Block a user