Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#27172 closed Cleanup/optimization (fixed)

Close cursor in custom SQL example

Reported by: Chris Jerdonek Owned by: Chris Jerdonek
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It would be better if here in this example, the cursor were explicitly closed (e.g. by using with connection.cursor() as cursor):

def my_custom_sql(self):
    cursor = connection.cursor()

    cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz])

    cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz])
    row = cursor.fetchone()

    return row

Change History (5)

comment:1 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

Is there any advantage to also updating the PollManager example in topics/db/managers.txt?

comment:2 by Chris Jerdonek, 8 years ago

Owner: changed from nobody to Chris Jerdonek
Status: newassigned

comment:3 by Berker Peksag, 8 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:4 by Claude Paroz <claude@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In ccf7adb:

Fixed #27172 -- Closed database cursor explicitly in two doc examples

comment:5 by Claude Paroz <claude@…>, 8 years ago

In d923733:

[1.10.x] Fixed #27172 -- Closed database cursor explicitly in two doc examples

Backport of ccf7adb064a70eb1b1ec5857f1dd54988f5c983c from master.

Note: See TracTickets for help on using tickets.
Back to Top