#26345 closed Cleanup/optimization (fixed)
Clarify that RangeFields always return canonical form of ranges
Reported by: | David Binetti | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Asked on #django to no response, so filing here.
When saving a postgres DateRange object to a DateRangeField, the bounds
are always changed to the default, even if a different bounds is requested. The date payload (upper or lower), is also changed according to the new bounds. This may be as designed, but it unexpected from my perspective.
For instance, my users may enter data in a form to express a two day event as Jan 1 2016 - Jan 2 2106, '[]' (inclusive lower and inclusive upper.) However, this is translated in the database as Jan 1 2016 - Jan 3 2016 '[)' (inclusive lower *exclusive* upper with changed date) so if I then try to render the upper date directly, it will do so as Jan 3, confusing the user (and the developer :-) !)
Yes, I could accommodate this with some display logic, but that strikes me as the wrong approach. I've included a repo with a test demonstrating what I was expecting to see.
Attachments (1)
Change History (7)
comment:1 by , 9 years ago
Summary: | Unexpected DateRange behavior → RangeFields always return canonical form of ranges |
---|
comment:2 by , 9 years ago
Certainly was unclear from my perspective. The word "default" suggests an initial position that is subject to further modification/override. Upon reading the Postgres docs, I now see that it is a canonicalization that is always returned, but even though I read that before I didn't fully understand what was happening on the back-end. It was unclear to me that the bounds is used to produce the canonicalization, but that the bounds themselves were not persisted.
Make of that what you will.
comment:3 by , 9 years ago
Component: | contrib.postgres → Documentation |
---|---|
Owner: | set to |
Summary: | RangeFields always return canonical form of ranges → Clarify that RangeFields always return canonical form of ranges |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
Feel free to propose some clarifications.
by , 9 years ago
Attachment: | 26345.patch added |
---|
comment:4 by , 9 years ago
Has patch: | set |
---|
Thanks for the draft, but this applies to IntegerRangeField
and BigIntegerRangeField
as well. Here's an alternate proposal.
From the PostgreSQL documentation:
Do we need to duplicate this information in Django's docs? Actually they do say, "The default is lower bound included, upper bound excluded." Maybe the implications of that statement are unclear?