#36031: DecimalRangeField __contains query for a value causes DataError
-------------------------------------+-------------------------------------
Reporter: Trent Holliday | Owner:
| amansharma612
Type: Bug | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Given the Postgres `numrange` type is continuous (it doesn't enforce a
discrete step) and thus doesn't allow defining `max_digits` or
`decimal_places` I would find it strange that we expose such attributes
that only happen to be used as a side effect of how the
`RangeContains.get_prep_lookup` method is implemented.
Adding these attributes would give a false sense that doing things like
{{{#!python
class Product(models.Model):
price_range = DecimalRangeField(max_digits=5, decimal_places=2)
Product.objects.create(price_range=["1999.99", "99999.99"])
}}}
Would be disallowed while `numrange` and the current implementation of
`DecimalRangeField` allows such value.
In other words, adding proper support for `max_digits` and
`decimal_places` would require quite a lot of work to get right as we
can't delegate to Postgres to get a discrete `numrange` which I don't
think is warranted here. We should either create a specialized
`DecimalRangeContains` lookup that casts to `::numeric` or go forward with
the proposed solution to have `Cast(expr, DecimalField())` to work (which
other users have also ran into #32593).
This lack of `numeric` parametrization is something we missed when we
introduced `DecimalRangeField` to replace the bogus `FloatRangeField`
(also backed by `numrange`) in #29598.
--
Ticket URL: <https://code.djangoproject.com/ticket/36031#comment:9>
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 visit
https://groups.google.com/d/msgid/django-updates/010701940436f5b2-080575ce-4078-4bc3-a19f-0f16155d770a-000000%40eu-central-1.amazonses.com.