diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-12 05:34:56 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-12 05:34:56 +0000 |
| commit | 220993bcc52e78520d8e6cc8aa022608eac10b2a (patch) | |
| tree | ce95383ebb30e67874dbe5b908e693086a4d60c3 /tests | |
| parent | e73bf2bdd9a6342e8bf10c78ca94415e02cb8838 (diff) | |
Added savepoint support to the transaction code.
This is a no-op for most databases. Only necessary on PostgreSQL so that we can
do things which will possibly intentionally raise an IntegrityError and not
have to rollback the entire transaction. Not supported for PostgreSQL versions
prior to 8.0, so should be used sparingly in internal Django code.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8314 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/force_insert_update/models.py | 8 | ||||
| -rw-r--r-- | tests/modeltests/one_to_one/models.py | 8 |
2 files changed, 6 insertions, 10 deletions
diff --git a/tests/modeltests/force_insert_update/models.py b/tests/modeltests/force_insert_update/models.py index feffed5faf..c9b9fe0c76 100644 --- a/tests/modeltests/force_insert_update/models.py +++ b/tests/modeltests/force_insert_update/models.py @@ -2,7 +2,7 @@ Tests for forcing insert and update queries (instead of Django's normal automatic behaviour). """ -from django.db import models +from django.db import models, transaction class Counter(models.Model): name = models.CharField(max_length = 10) @@ -40,15 +40,13 @@ ValueError: Cannot force an update in save() with no primary key. >>> c1.save(force_insert=True) # Won't work because we can't insert a pk of the same value. +>>> sid = transaction.savepoint() >>> c.value = 5 >>> c.save(force_insert=True) Traceback (most recent call last): ... IntegrityError: ... - -# Work around transaction failure cleaning up for PostgreSQL. ->>> from django.db import connection ->>> connection.close() +>>> transaction.savepoint_rollback(sid) # Trying to update should still fail, even with manual primary keys, if the # data isn't in the database already. diff --git a/tests/modeltests/one_to_one/models.py b/tests/modeltests/one_to_one/models.py index 6fa4dd8c18..348a543c52 100644 --- a/tests/modeltests/one_to_one/models.py +++ b/tests/modeltests/one_to_one/models.py @@ -6,7 +6,7 @@ To define a one-to-one relationship, use ``OneToOneField()``. In this example, a ``Place`` optionally can be a ``Restaurant``. """ -from django.db import models, connection +from django.db import models, transaction class Place(models.Model): name = models.CharField(max_length=50) @@ -178,13 +178,11 @@ DoesNotExist: Restaurant matching query does not exist. # This will fail because each one-to-one field must be unique (and link2=o1 was # used for x1, above). +>>> sid = transaction.savepoint() >>> MultiModel(link1=p2, link2=o1, name="x1").save() Traceback (most recent call last): ... IntegrityError: ... +>>> transaction.savepoint_rollback(sid) -# Because the unittests all use a single connection, we need to force a -# reconnect here to ensure the connection is clean (after the previous -# IntegrityError). ->>> connection.close() """} |
