[Django] #32705: Database cache.delete uses cursor after it is closed

31 views
Skip to first unread message

Django

unread,
May 2, 2021, 5:27:17 AM5/2/21
to django-...@googlegroups.com
#32705: Database cache.delete uses cursor after it is closed
------------------------------------------------+------------------------
Reporter: ecogels | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
The return bool(cursor.rowcount) is outside of the with block, so the
cursor will have been closed at that point.

From the DB API 2.0 spec: "The cursor will be unusable from this point
forward" https://www.python.org/dev/peps/pep-0249/#Cursor.close


As the main backend drivers don't mind it I suppose that is is open to
interpretation.


Here is a basic PR
https://github.com/django/django/compare/main...ecogels:fix-dbcache-
delete-1

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

Django

unread,
May 3, 2021, 11:23:01 AM5/3/21
to django-...@googlegroups.com
#32705: Database cache.delete uses cursor after it is closed
--------------------------------------+------------------------------------

Reporter: ecogels | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/32705#comment:1>

Django

unread,
May 3, 2021, 2:16:32 PM5/3/21
to django-...@googlegroups.com
#32705: Database cache.delete uses cursor after it is closed
--------------------------------------+------------------------------------

Reporter: ecogels | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Description changed by ecogels:

Old description:

> The return bool(cursor.rowcount) is outside of the with block, so the
> cursor will have been closed at that point.
>
> From the DB API 2.0 spec: "The cursor will be unusable from this point
> forward" https://www.python.org/dev/peps/pep-0249/#Cursor.close
>

> As the main backend drivers don't mind it I suppose that is is open to
> interpretation.
>

New description:

The return bool(cursor.rowcount) is outside of the with block, so the
cursor will have been closed at that point.

From the DB API 2.0 spec: "The cursor will be unusable from this point
forward" https://www.python.org/dev/peps/pep-0249/#Cursor.close


As the main backend drivers don't mind it I suppose that is is open to
interpretation.


PR https://github.com/django/django/pull/14341

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32705#comment:2>

Django

unread,
May 5, 2021, 6:43:30 AM5/5/21
to django-...@googlegroups.com
#32705: Database cache.delete uses cursor after it is closed
-------------------------------------+-------------------------------------
Reporter: ecogels | Owner: ecogels
Type: | Status: assigned
Cleanup/optimization |

Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => ecogels
* status: new => assigned
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32705#comment:3>

Django

unread,
May 5, 2021, 7:40:23 AM5/5/21
to django-...@googlegroups.com
#32705: Database cache.delete uses cursor after it is closed
-------------------------------------+-------------------------------------
Reporter: ecogels | Owner: ecogels
Type: | Status: closed
Cleanup/optimization |

Component: Core (Cache system) | Version: 3.2
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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"a0a5e0f4c83acdfc6eab69754e245354689c7185" a0a5e0f4]:
{{{
#!CommitTicketReference repository=""
revision="a0a5e0f4c83acdfc6eab69754e245354689c7185"
Fixed #32705 -- Prevented database cache backend from checking .rowcount
on closed cursor.

Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32705#comment:4>

Reply all
Reply to author
Forward
0 new messages