(Discussion is happening here): http://groups.google.com/group/django-users/browse_thread/thread/8004a40b3c607d08/7b7ed19d276033df
Postgresql does error handling inside transactions differently than mySQL and sqlite. When using the latter two, you can do this inside a transaction:
class MyModel(Model):
uniquefield = CharField(max_length=200,unique=True)
MyModel.objects.create(uniquefield='Some non-unique value')
try:
MyModel.objects.create(uniquefield='Some non-unique value')
except:
MyModel.objects.create(uniquefield='A unique value')
while in postgres the last query will fail as well.
Note that postgresql is by default inside a transaction - ticket #3460 is aimed at fixing this.
I believe the solution is to wrap the "execute" method to generate savepoints when inside a transaction. Something like the following (untested) pseudocode:
def myexecute(self, *args,**kwargs):
if self.is_in_transaction:
self.create_save_point(identifier)
try:
self.execute(*args,**kwargs)
except DatabaseError,e:
self.rollback(identifier)
raise
else:
self.execute(*args,**kwargs)