Ticket #8739: 8739_save_force_insert.v2.diff

File 8739_save_force_insert.v2.diff, 1.3 KB (added by Richard Davies <richard.davies@…>, 16 years ago)

Agreed with Malcolm that this ticket was a mistake. Before I sign off, here's a test case for force_insert functionality only, which _does_ do the transaction management itself, and succeeds on both databases

  • tests/regressiontests/save_force_insert/models.py

     
     1from django.db import models, transaction, IntegrityError
     2
     3class ManualPrimaryKeyTest(models.Model):
     4    id = models.IntegerField(primary_key=True)
     5    data = models.CharField(max_length=100)
     6
     7__test__ = {'API_TESTS':"""
     8# If you force_insert specifying an existing primary key, but different
     9# other fields, then you will get an error and data will not be updated.
     10>>> m = ManualPrimaryKeyTest(id=1, data='Original')
     11>>> m.save(force_insert=True)
     12>>> try:
     13...    m = ManualPrimaryKeyTest(id=1, data='Different')
     14...    sid = transaction.savepoint()
     15...    m.save(force_insert=True)
     16...    transaction.savepoint_commit(sid)
     17... except Exception, e:
     18...    if isinstance(e, IntegrityError):
     19...        transaction.savepoint_rollback(sid)
     20...        print "Pass"
     21...    else:
     22...        print "Fail with %s" % type(e)
     23Pass
     24>>> ManualPrimaryKeyTest.objects.get(id=1).data == 'Original'
     25True
     26"""}
Back to Top