On 31 Mar, 06:04, Continuation <selforgani...@gmail.com> wrote: > On Mar 30, 8:33 am, Tomasz Zieliñski > > <tomasz.zielin...@pyconsultant.eu> wrote: > > If you take a look at TransactionMiddleware source: > > >http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan... > > > then you'll see that it's just commit_on_success in disguise: > > >http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan... > > So that means I don't need TransactionMiddleware if I use > @transaction.commit_on_success, right?
If you put @transaction.commit_on_success explicitly in your code, then you're doing TransactionMiddleware manually, so the answer is yes. > > > Also, you can take a look at my post here, to avoid some transaction- > > related problems in future: > > >http://stackoverflow.com/questions/2235318/how-do-i-deal-with-this-ra... > > Thanks. > > I assume that calling transaction.commit() after the IntegrityError > exception is to refresh the frozen view. But I'm not sure I understand > why transaction.commit() would do that. Can you elaborate? Because on default MySQL isolation level, i.e. REPEATABLE READ, view (or snapshot) of db table is frozen after first access to it (there are some more detail's to it). To get new snapshot you have to open new transaction, and that's what commit do. http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read (Note that in above link they say about SELECT, and I don't remember if create() also SELECTs or it's INSERT that freezes table, but the fact is table become frozen for transaction). > > Also in your stackoverflow answer you said the default for MySQL is > AUTOCOMMIT=OFF. but in the Django doc (http://docs.djangoproject.com/ > en/dev/topics/db/transactions/) it was stated that > > "Django's default behavior is to run with an open transaction which it > commits automatically... This is much like the auto-commit setting for > most databases." > > So is auto-commit on or off by default? It's the tricky part. There are *two* auto-commits - one is in DB, and second one is in Django. Autocommit in DB is OFF by default (according to Python DB API spec, and Django doesn't seem to change that), whereas Django autocommit is turned ON by default (and documentation is not clear here). DB autocommit is something you can read about in DB docs, (for MySQL Innodb: http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-model.html) where as Django autocommit is simple mechanism that calls db COMMIT after each query that modifies db (e.g. INSERT caused by save()) - and that's the whole magic. -- Tomasz Zielinski http://pyconsultant.eu -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.