gian paolo ciceri wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> Oleg Broytmann wrote:
> | On Sat, Feb 12, 2005 at 08:21:00PM +0100, gian paolo ciceri wrote:
> |>It is difficult for me to understand why, without a specific reason,
> |>I've to re-create a transaction after a commit
> | I do not understand the question. In my code, at least, I never
> | recreate the transaction.
> | Oleg.
> Oleg, you're right.
> I've re-checked the code snippet I sent to the ML this morning
> when I was not aware of this side effect because of the asymmetric
> behaviour of commit() and rollback()
> Please let me re-paste and annotate to explain:
> - ----
> ~ 1 trx = conn.transaction()
> ~ 2
> ~ 3 p2 = Person.get(39, trx)
> ~ 4 print p2
> ~ 5 p2.middleInitial = 'k'
> ~ 6 trx.commit()
> ~ 7
> ~ 8 ### here I must create a new transaction <--- WRONG
> ~ 9 trx = conn.transaction()
> 11 ### I cannot simply begin another <--- WRONG
> 12 #trx.begin()
> 13 p2.middleInitial = 'q'
> 14 trx.rollback()
> 15 <--- HERE I'VE NOT CALLED trx.begin()
> 16 print 'rollback:', p2 <--- and I ask for p2, still under trx.
> - ----
> Since commit() does not require a successive begin()
> while rollback does, I've solved the problem at line 15
> (lack of a begin() after a rollback()) using another,
> different transacion, initiated at line 9,
> (in fact if you try to debug=1 the connection, you'll see two
> different ones). From this point I *wrongly* inferred you
> need to re-create the transaction after the commit.
> At this point a wrapper like yours is needed to be sure
> to begin() the transaction after the rollback().
In my mind, it was because commit means "everything is good, make this
work permanent", while a rollback is like a failure. I guess. It's
also because a rollback effects all your objects, and places your
application state into kind of a limbo. _makeObsolete probably doesn't
go far enough. At least .begin() makes you think consciously about
using that connection anymore.
Honestly, I don't use transactions that much, so I don't have a strong
intuition about it. At least the failure messages should be better if
you make the kind of mistakes you have made. Feel free to file a bug
> I still have to understand the reason for this
> different behaviour between commit() and rollback()
> in the library, but almost now all the samples make sense.
Ian Bicking / ianb@... / http://blog.ianbicking.org