Re: [Django] #36078: Document that Postgres normalizes a range field with no points normalizes to empty

15 views
Skip to first unread message

Django

unread,
Jan 13, 2025, 10:06:54 AMJan 13
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
--------------------------------------+------------------------------------
Reporter: Mapiarz | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Mapiarz):

I agree. There should be an explicit warning about this. It's really easy
to be caught of guard by this and lose data.

I do not understand why psycopg opted out of normalizing the value to
empty, just like postgres does. I have raised this issue here:
https://github.com/psycopg/psycopg/discussions/993
--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 13, 2025, 1:23:37 PMJan 13
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
--------------------------------------+------------------------------------
Reporter: Mapiarz | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Daniele Varrazzo):

> I agree. There should be an explicit warning about this. It's really
easy to be caught of guard by this and lose data.

You are already losing data, because if you are calling
`DateTimeTZRange('2025-01-01', '2025-01-31')` to mean the whole month of
January you are losing a day, because the default bounds are `[)` so the
31st is not in the range, the same way that 4 is not in the `[4,4)` range.
The data loss comes from using the wrong bounds, not from the
normalization rules, which are the same whether implemented by Python or
by Postgres.

In the above example, `DateTimeTZRange(now, now, '[]')` might have been
what you wanted.

> I do not understand why psycopg opted out of normalizing the value to
empty, just like postgres does. I have raised this issue here:
https://github.com/psycopg/psycopg/discussions/993

I have left a response on the psycopg tracker. I am -0.5 to introduce
normalization in Python, but, regardless from that, I don't think it would
have resulted in any difference w.r.t. the issue explained here. If we had
returned what the OP expected to receive it would have meant we have a bug
as Psycopg normalization would disagree with Postgres one.
--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:6>

Django

unread,
Jan 15, 2025, 9:59:08 AMJan 15
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* owner: (none) => Clifford Gama
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:7>

Django

unread,
Jan 16, 2025, 7:13:57 AMJan 16
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/19056 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:8>

Django

unread,
Mar 17, 2025, 10:31:09 AMMar 17
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:9>

Django

unread,
Mar 17, 2025, 11:45:57 AMMar 17
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:10>

Django

unread,
Mar 18, 2025, 9:50:02 AMMar 18
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:11>

Django

unread,
Mar 18, 2025, 11:50:03 AMMar 18
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: closed
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: postgres | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"611e7bc3a0633a35ae3430e359c646e02fa3801d" 611e7bc3]:
{{{#!CommitTicketReference repository=""
revision="611e7bc3a0633a35ae3430e359c646e02fa3801d"
Fixed #36078 -- Doc'd that Postgres normalizes a range field with no
points to empty.

Co-authored-by: Sarah Boyce <42296566+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:12>

Django

unread,
Mar 18, 2025, 11:51:46 AMMar 18
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: closed
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: postgres | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"428cb3afd6ff9f5911bbf98aaf8e57bbfd85a4fb" 428cb3af]:
{{{#!CommitTicketReference repository=""
revision="428cb3afd6ff9f5911bbf98aaf8e57bbfd85a4fb"
[5.2.x] Fixed #36078 -- Doc'd that Postgres normalizes a range field with
no points to empty.

Co-authored-by: Sarah Boyce <42296566+...@users.noreply.github.com>

Backport of 611e7bc3a0633a35ae3430e359c646e02fa3801d from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:13>

Django

unread,
Mar 18, 2025, 11:53:42 AMMar 18
to django-...@googlegroups.com
#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
-------------------------------------+-------------------------------------
Reporter: Mapiarz | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: closed
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: postgres | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"d05cf7c35ff5fc2781962f06051c0df072201a78" d05cf7c3]:
{{{#!CommitTicketReference repository=""
revision="d05cf7c35ff5fc2781962f06051c0df072201a78"
[5.1.x] Fixed #36078 -- Doc'd that Postgres normalizes a range field with
no points to empty.

Co-authored-by: Sarah Boyce <42296566+...@users.noreply.github.com>

Backport of 611e7bc3a0633a35ae3430e359c646e02fa3801d from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36078#comment:14>
Reply all
Reply to author
Forward
0 new messages