Transaction context manager patch

Bug #583656 reported by Denis Malinovsky on 2010-05-21
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fix Released
Nikoleta Verbeck

Bug Description

It's not a bug really, but proposal, with a patch.

As you know Python 2.5 introduced handy 'with' statement. It's ideal candidate for use with transactions, something like this:
q = PySQLPool.getNewQuery(connection)
with q: # internal queries are wrapped into transaction
            q.Query('INSERT INTO peer SET PeerName=%s', (name,))

I attached the patch, hope it'll be useful.

Denis Malinovsky (dmalinovsky) wrote :
Changed in pysqlpool:
importance: Undecided → Critical
status: New → In Progress
assignee: nobody → Nick Verbeck (nerdynick)
milestone: none → 0.3.6
Changed in pysqlpool:
status: In Progress → Fix Committed
Nikoleta Verbeck (nerdynick) wrote :

Your patch is applied and committed to the 0.3.6 Release. Which I'm hoping to release very soon. Just need to wrap up the documentation effort that is the main focus of the release.

I have to say, I never even gave the with statement a thought when it came to transactions. Not a bad idea. There is 1 bug in your implementation but this more relates to a bug I have with transactions in general when it comes to PySQLPool. The 0.4 release should fix the whole transaction model. Currently the problem is when you have multiple connections going out to 1 DB. There is nothing that locks a connection to 1 query object. So some other thread could end up getting into your transaction.

Denis Malinovsky (dmalinovsky) wrote :

I'm glad you like it.

I thought when I'm getting new query, new connection goes with it as well, isn't it? Then it's bug really.

Nikoleta Verbeck (nerdynick) wrote :

So the new connection object you are creating is just a helper object and doesn't actaully create a new connection. It just acts as a common connection information storage and key generation for the pool.

Changed in pysqlpool:
status: Fix Committed → Fix Released
Nikoleta Verbeck (nerdynick) wrote :

This change has been released now in the 0.3.6 release.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers