I have the following piece of code overriding the save method of a model:
@transaction.commit_on_success
def save(self, *args, **kwargs):
try:
transaction.commit()
self.qa.vote_down_count += 1
self.qa.save()
super(self.__class__, self).save(*args, **kwargs)
except:
transaction.rollback()
raise
else:
transaction.commit()
The expected behavior would be: self.qa attribute vote_down_count is incremented by one, but if any exception occurs in the super(self) save method the transaction rollbacks (that means the self.qa.vote_down_count += 1 is not committed in the database).
The actual behavior is: self.qa.vote_down_count += 1 is committed to database even if an IntegrityError exception raises from super(self) save.
Any thoughs?