[Django] #28853: Use database cursor as a context manager internally

1 view
Skip to first unread message

Django

unread,
Nov 28, 2017, 8:23:06 AM11/28/17
to django-...@googlegroups.com
#28853: Use database cursor as a context manager internally
------------------------------------------------+------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
While reading the code Django code, I noticed some uses of
`connection.cursor()` weren't being used as a context manager. For
example:

https://github.com/django/django/blob/4f5526e346861c0b2ffa2ea7229747c883e14432/django/test/testcases.py#L855-L857

{{{
def _reset_sequences(self, db_name):
...
cursor = conn.cursor()
for sql in sql_list:
cursor.execute(sql)
}}}

This pattern exists multiple time throughout Django. Using a context
manager helps ensure resources are closed deterministically and that
errors aren't hidden.

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

Django

unread,
Nov 28, 2017, 8:30:00 AM11/28/17
to django-...@googlegroups.com
#28853: Use database cursor as a context manager internally
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Uncategorized | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jon Dufresne):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9394 PR]

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

Django

unread,
Nov 28, 2017, 11:50:04 AM11/28/17
to django-...@googlegroups.com
#28853: Use database cursor as a context manager internally
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(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 felixxm):

* component: Uncategorized => Database layer (models, ORM)
* stage: Unreviewed => Accepted


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

Django

unread,
Nov 28, 2017, 12:17:20 PM11/28/17
to django-...@googlegroups.com
#28853: Use database cursor as a context manager internally
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(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 felixxm):

* stage: Accepted => Ready for checkin


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

Django

unread,
Nov 28, 2017, 1:54:22 PM11/28/17
to django-...@googlegroups.com
#28853: Use database cursor as a context manager internally
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"7a6fbf36b1fdb8978ea0842075ccce83bcd63789" 7a6fbf3]:
{{{
#!CommitTicketReference repository=""
revision="7a6fbf36b1fdb8978ea0842075ccce83bcd63789"
Fixed #28853 -- Updated connection.cursor() uses to use a context manager.
}}}

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

Reply all
Reply to author
Forward
0 new messages