Re: [Django] #34858: Output field for combined PositiveIntegerField is not properly resolved.

20 views
Skip to first unread message

Django

unread,
Sep 21, 2023, 4:26:52 PM9/21/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Toan Vuong):

Thanks for the reply! I can work on a PR for the `PositiveIntegerField`
change following the patch you wrote.

However, regarding your statement:

> Coalesce() on Oracle checks the output_field of arguments and crashes

This seems incorrect, because using `Coalesce` alone would crash on both
Postgres and Oracle. The weird thing is if I have a `Case` on top of the
"bad" `Coalesce`, then only Oracle crashes. The Postgres queryset executes
successfully. So it seems like `Case` behaves differently between the
two, and probably incorrectly swallows the error thrown by `Coalesce` in
the Postgres scenario which also seems like a bug?

--
Ticket URL: <https://code.djangoproject.com/ticket/34858#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 21, 2023, 4:29:54 PM9/21/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Toan
| Vuong
Type: Bug | Status: assigned

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Toan Vuong):

* owner: nobody => Toan Vuong
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34858#comment:5>

Django

unread,
Sep 21, 2023, 7:17:50 PM9/21/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Toan
| Vuong
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by Toan Vuong):

* has_patch: 0 => 1


Comment:

Opened a PR:
https://github.com/django/django/pull/17296

Still wondering about whether we need to do something about `Case` between
Postgres vs. Oracle, because the behavior still seems inconsistent there.

--
Ticket URL: <https://code.djangoproject.com/ticket/34858#comment:6>

Django

unread,
Sep 22, 2023, 3:15:50 AM9/22/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Toan
| Vuong
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
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 Mariusz Felisiak):

Replying to [comment:6 Toan Vuong]:


> Still wondering about whether we need to do something about `Case`
between Postgres vs. Oracle, because the behavior still seems inconsistent
there.

`Coalesce()` on Oracle
[https://github.com/django/django/blob/d7972436639bacada0f94d3b9818446343af59ad/django/db/models/functions/comparison.py#L93
explicitly checks] the `output_field` when it's compiled (for
`Cast.default)`, on other database the `output_field` is not used when
`Coalesce()` is compiled so it doesn't crash. The crash on Oracle is a
side-effect of the current implementation, IMO, there is no need to change
it.

> Edit: Also not sure what the process is to open PRs for other
branches(?). Seems like I should also merge this to main and stable/5.0.x?

Mergers will backport if needed.

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

Django

unread,
Sep 22, 2023, 3:22:58 AM9/22/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Toan
| Vuong
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | 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 Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34858#comment:8>

Django

unread,
Sep 22, 2023, 4:09:12 AM9/22/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Toan
| Vuong
Type: Bug | Status: closed

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | 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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"4de31ec680df062e5964b630f1b881ead5004e15" 4de31ec]:
{{{
#!CommitTicketReference repository=""
revision="4de31ec680df062e5964b630f1b881ead5004e15"
Fixed #34858 -- Corrected resolving output_field for PositiveIntegerField.

Regression in 40b8a6174f001a310aa33f7880db0efeeb04d4c4.
}}}

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

Django

unread,
Sep 22, 2023, 4:09:41 AM9/22/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Toan
| Vuong
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | 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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"dcd3a0316bed8605c0464793cd7ca73027eaa780" dcd3a03]:
{{{
#!CommitTicketReference repository=""
revision="dcd3a0316bed8605c0464793cd7ca73027eaa780"
[5.0.x] Fixed #34858 -- Corrected resolving output_field for
PositiveIntegerField.

Regression in 40b8a6174f001a310aa33f7880db0efeeb04d4c4.

Backport of 4de31ec680df062e5964b630f1b881ead5004e15 from main
}}}

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

Django

unread,
Sep 22, 2023, 11:14:03 AM9/22/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Toan
| Vuong
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | 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 Toan Vuong):

> Coalesce() on Oracle ​explicitly checks the output_field when it's
compiled (for Cast.default), on other database the output_field is not


used when Coalesce() is compiled so it doesn't crash. The crash on Oracle
is a side-effect of the current implementation, IMO, there is no need to
change it.

Thanks, this is what I was missing. In our local copy of Django I
essentially added a try/catch on that `as_oracle` function which worked,
but I didn't realize that was only called in some cases but not others.

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

Reply all
Reply to author
Forward
0 new messages