Re: [Django] #34260: models.FloatField documentation doesn't mention that +inf, -inf, and NaN are invalid. (was: Field reference documentation doesn't mention that +inf, -inf, and NaN are invalid)

5 views
Skip to first unread message

Django

unread,
Jan 15, 2023, 11:54:54 PM1/15/23
to django-...@googlegroups.com
#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.

Reply all
Reply to author
Forward
0 new messages