I'm trying to use Django transactions on MySQL with the commit_on_success
decorator. According to the documentation, "If the function raises an exception, though, Django will roll back the transaction." However, this doesn't seem to work for me:
>>> @transaction.commit_on_success
... def fails():
... Site.objects.create(name="New Site", ip_address="127.0.0.1")
... raise ValueError("oh noes!")
...
>>> Site.objects.count()
2
>>> fails()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/django/db/transaction.py", line 240, in _commit_on_success
res = func(*args, **kw)
File "<stdin>", line 4, in fails
ValueError: oh noes!
>>> Site.objects.count()
3
>>>
I'm pretty sure that MySQL supports transactions; do I need to use a different table type or something?