summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-03-12 14:27:31 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-03-12 14:27:31 +0000
commit1e1b57bfbe3a493d2179d499f00b0bbba49b8e2d (patch)
treed1a752082bf9fecacc60d750aa5c6d6eadeb003b /tests
parent9137c54353f3356e0f65e0218016e92c5bc9cc43 (diff)
[1.1.X] Fixed #11900 -- Corrected an edge case of transaction handling in the commit_on_success decorator. Thanks to guettli for the report, and Gabriel Hurley for the initial test case.
Backport of r12764 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12765 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/transactions/models.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/modeltests/transactions/models.py b/tests/modeltests/transactions/models.py
index 6763144ca5..9f32776f26 100644
--- a/tests/modeltests/transactions/models.py
+++ b/tests/modeltests/transactions/models.py
@@ -100,3 +100,23 @@ Traceback (most recent call last):
...
TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
"""
+
+# Regression for #11900: If a function wrapped by commit_on_success writes a
+# transaction that can't be committed, that transaction should be rolled back.
+# The bug is only visible using the psycopg2 backend, though
+# the fix is generally a good idea.
+if building_docs or settings.DATABASE_ENGINE == 'postgresql_psycopg2':
+ __test__['API_TESTS'] += """
+>>> def execute_bad_sql():
+... cursor = connection.cursor()
+... cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
+... transaction.set_dirty()
+...
+>>> execute_bad_sql = transaction.commit_on_success(execute_bad_sql)
+>>> execute_bad_sql()
+Traceback (most recent call last):
+ ...
+IntegrityError: null value in column "email" violates not-null constraint
+<BLANKLINE>
+
+"""