#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.433d762e25a80d6595185e245dc71f28%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to