#34260: models.FloatField documentation doesn't mention that +inf, -inf, and NaN
are invalid.
-------------------------------------+-------------------------------------
Reporter: Matt Cooper | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: invalid
Keywords: floatfield | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => invalid
Comment:
Storing `inf`, `-inf`, and `nan` in `FloatField` works for me, I don't see
any protection against them in `models.FloatField`:
{{{#!diff
diff --git a/tests/model_fields/test_floatfield.py
b/tests/model_fields/test_floatfield.py
index 264b5677e9..e3b3fde380 100644
--- a/tests/model_fields/test_floatfield.py
+++ b/tests/model_fields/test_floatfield.py
@@ -1,3 +1,5 @@
+import math
+
from django.db import transaction
from django.test import TestCase
@@ -31,6 +33,16 @@ class TestFloatField(TestCase):
with self.assertRaisesMessage(TypeError, msg):
obj.save()
+ def test_save_inf(self):
+ for value in [float("inf"), math.inf, "inf"]:
+ FloatModel.objects.create(size=value)
+ for value in [float("-inf"), -math.inf, "-inf"]:
+ FloatModel.objects.create(size=value)
+
+ def test_save_nan(self):
+ for value in [float("nan"), math.nan, "nan"]:
+ FloatModel.objects.create(size=value)
+
def test_invalid_value(self):
tests = [
(TypeError, ()),
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34260#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070185b8ee1778-10649ebc-f88a-44f8-b838-0c09703b001b-000000%40eu-central-1.amazonses.com.