#32967 closed Bug (wontfix)
Buggy Migrations when `float("nan")` in `Q` objects
Reported by: | Steven Jin | Owned by: | Steven Jin |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.2 |
Severity: | Normal | Keywords: | db Q |
Cc: | Steven Jin | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When creating a CheckConstraint
in the form
class MyModel(Model): x = FloatField() class Meta: constraints = [~CheckConstraint(check=Q(x=float("nan")), name="some constraint")]
This constraint is removed and added back every time python manage.py makemigrations
is run. This is because the inherited __eq__
function of Q
objects does not take into account the fact that float("nan") != float("nan")
.
Change History (9)
comment:1 by , 3 years ago
Description: | modified (diff) |
---|
comment:2 by , 3 years ago
Summary: | Buggy Migrations when `flota("nan")` in `Q` objects → Buggy Migrations when `float("nan")` in `Q` objects |
---|
comment:3 by , 3 years ago
Cc: | added |
---|---|
Description: | modified (diff) |
Has patch: | set |
Resolution: | → fixed |
Status: | assigned → closed |
comment:4 by , 3 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
comment:5 by , 3 years ago
Status: | new → assigned |
---|
comment:6 by , 3 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
comment:7 by , 3 years ago
Thanks for the reply! How would I ensure that values in a column are not nan
?
follow-up: 9 comment:8 by , 3 years ago
Have you tried to simply compare against the NaN
string?
~CheckConstraint(check=Q(x='NaN'), name="not_nan")
It seems to work for me on PostgreSQL.
comment:9 by , 3 years ago
Thanks!
Replying to Simon Charette:
Have you tried to simply compare against the
NaN
string?
~CheckConstraint(check=Q(x='NaN'), name="not_nan")It seems to work for me on PostgreSQL.
Thanks for the report, however it looks like a hypothetical issue, what do you want to check with such constraint? (
float('nan') != whatever)
.FloatField
uses a proper data type and this should be ensured on a database layer without extra constraints. I don't think it's worth additional complexity.