Getting benifits of database transactions in an OO way?

Leif K-Brooks eurleif at
Sun Aug 22 03:31:22 CEST 2004

Paul Rubin wrote:
> Leif K-Brooks <eurleif at> writes:
>>Right now, the Person.save_data method also commits the current
>>database transaction. But that seems to remove the benifit of having a
>>database with transactions: If something dies between the call to
>>fred.save_data() and barney.save_data(), Fred's $10 will end up in a
>>black hole somewhere.
> You have to use transactions for that.  E.g.
>     import people
>     this_transaction = people.begin_transaction()
>     fred = this_transaction.find_by_name('Fred Flintstone')
>     barney = this_transaction.find_by_name('Barney Rubble')
> -= 10
> += 10
>     this_transaction.finish_transaction()

How woould begin_transaction() and finish_transaction() be implemented? 
They couldn't be simple wrappers for PostgreSQL transaction handling, 
since it's not very object-oriented (the whole connection has one 
transaction at a time).

More information about the Python-list mailing list