473,287 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

SQLObject transaction rollback not working

Hello. I'm trying to wrap a function call in a transaction, but when I
intentionally throw an exception in the middle of the function it
doesn't actually roll back the transaction. The debug output says
1/ROLLBACK, without any 1/COMMITs in there, but when I view the data in
the command-line mysql utility the changes have been made.

This is the code I'm using to connect to the mysql database and to wrap
the function call in a transaction. After that I've invluded the
testUpdate method I'm using, and after that the python conversation
that ensued. Does anyone see what I'm doing wrong?

--- sqlutil.py:

from sqlobject import *

def connect():
""" Connects SQLObject to the dev database on localhost.
"""
connectionString =
"mysql://admin@localhost/mc_image_library_dev?debug=1"
connection = connectionForURI (connectionString)
sqlhub.processConnection = connection
def wrapInTransaction (func, *args, **kw):
""" Got this from the SQLObject mailing list.
Calls the given func with the given args and keyword assignments
within a db transaction. Rolls back if an exception is thrown,
otherwise commits.
"""
old_conn = sqlhub.getConnection()
conn = old_conn.transaction()
sqlhub.processConnection = conn
try:
try:
value = func(*args, **kw)
except:
conn.rollback()
raise
else:
conn.commit()
return value
finally:
sqlhub.processConnection = old_conn

------------------
----- test.py:

from ImageCategory import *

def testUpdate (newName, username, fail):
category = ImageCategory.get(1)
category.name = newName
category.updateLastChanged (username)
if fail:
raise Exception ('spam', 'eggs')

-----------------
------ The python conversation:
import sqlutil
sqlutil.connect()
import test
sqlutil.wrapInTransaction (test.testUpdate, 'Animals', 'jake', True)

1/QueryOne: SELECT last_changed_by, last_changed_date, name FROM
image_category WHERE id = 1
1/Query : UPDATE image_category SET name = 'Animals' WHERE id = 1
1/Query : UPDATE image_category SET last_changed_by = 'jake' WHERE
id = 1
1/Query : UPDATE image_category SET last_changed_date = '2005-11-29
00:36:22' WHERE id = 1
1/ROLLBACK:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "sqlutil.py", line 22, in wrapInTransaction
value = func(*args, **kw)
File "test.py", line 8, in testUpdate
raise Exception ('spam', 'eggs')
Exception: ('spam', 'eggs')

------------

After all this, the mysql utility shows that the update did take
effect.

Any thoughts?

- Jake

Nov 29 '05 #1
1 2986
ja*********@gmail.com wrote:
Does anyone see what I'm doing wrong?


Using MySQL? Are you aware that MySQL doesn't support transaction
handling with COMMIT and ROLLBACK in all configurations. It depends
on your MySQL version and what table backend you are using.

The Python DB-API states that autocommit should be turned off by
default, so if your tables support that, it should work right in
MySQLdb. SQLObject on the other hand, turns autocommit on by
default, so that could be the cuplrit if the problem is that you
didn't read the SQLObject docs... ;)

See
http://www.sqlobject.org/SQLObject.h...ring-the-class
"Parameters are: debug (default: False), debugOutput (default: False),
cache (default: True), autoCommit (default: True), debugThreading
(default: False)."

You might need to turn off both cache and autocommit to get things
to work right.
Dec 5 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? ...
7
by: Abdul-Wahid Paterson | last post by:
Hi, I have had a site working for the last 2 years and have had no problems until at the weekend I replace my database server with a newer one. The database migration went like a dream and I had...
2
by: jacob.miles | last post by:
I'm trying to connect to a mysql database, with autoCommit and caching off, and I'm trying to create a transaction. Why does this blow up? >>> from sqlobject import * >>> connectionString =...
1
by: Matik | last post by:
Hi to all, Probably I'm just doing something stupid, but I would like you to tell me that (if it is so), and point the solution. There ist the thing: I' having a sp, where I call other sp...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.7.1 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as...
3
by: Ralf Assmann | last post by:
Hi there, we have the following problem using a DB2 version 7 on z/OS, referring also <a...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0b1 release of SQLObject. This is the first beta of the new branch. Taking into account that it is a result of rather large job the beta period will be...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as...
3
by: GaryDean | last post by:
I'm using TransactionScope as follows... using TransactionScope myScope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString =...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.