summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
authorMichael Manfre <mmanfre@gmail.com>2013-09-23 20:17:59 -0400
committerAnssi Kääriäinen <akaariai@gmail.com>2013-09-25 21:47:26 +0300
commit99c87f1410106ce543a1a0332428afc472beef7f (patch)
treeee2c17e7f246e842ede59c45af504209c036170d /docs/topics
parent04a2a6b0f9cb6bb98edfe84bf4361216d60a4e38 (diff)
Fixed #17671 - Cursors are now context managers.
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/db/sql.txt27
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt
index 7437d51d28..1369ed84f5 100644
--- a/docs/topics/db/sql.txt
+++ b/docs/topics/db/sql.txt
@@ -297,3 +297,30 @@ database library will automatically escape your parameters as necessary.
Also note that Django expects the ``"%s"`` placeholder, *not* the ``"?"``
placeholder, which is used by the SQLite Python bindings. This is for the sake
of consistency and sanity.
+
+.. versionchanged:: 1.7
+
+:pep:`249` does not state whether a cursor should be usable as a context
+manager. Prior to Python 2.7, a cursor was usable as a context manager due
+an unexpected behavior in magic method lookups (`Python ticket #9220`_).
+Django 1.7 explicitly added support to allow using a cursor as context
+manager.
+
+.. _`Python ticket #9220`: http://bugs.python.org/issue9220
+
+Using a cursor as a context manager:
+
+.. code-block:: python
+
+ with connection.cursor() as c:
+ c.execute(...)
+
+is equivalent to:
+
+.. code-block:: python
+
+ c = connection.cursor()
+ try:
+ c.execute(...)
+ finally:
+ c.close() \ No newline at end of file