rollback is not working for me. I wrote a small test script that
inserts two rows, with the second row creating a violation. Upon
throwing exception, I would expect no rows to be inserted due to
rollback, but I find that the first insert is persisted. The
surprising thing is that the echo output clearly says that sqlalchemy
has rollbacked the transaction. Please help.
======
CODE:
=============================================================================
trans = connection.begin()
try:
ins = table.insert().values(id=122, name='k',
tt_start='20100101', tt_end='20100101',
vt_start='20100101',
vt_end='20100101')
connection.execute(ins)
ins = table.insert().values(id=121, name='k')
connection.execute(ins)
trans.commit()
except:
trans.rollback()
raise
==========
OUTPUT:
===============================================================================
[20110112 19:15:51:203 base.py:723 INFO] BEGIN
INSERT INTO bbb (id, name, tt_start, tt_end, vt_start, vt_end) VALUES
(?, ?, ?, ?, ?, ?)
[20110112 19:15:51:205 base.py:945 INFO] INSERT INTO bbb (id, name,
tt_start, tt_end, vt_start, vt_end) VALUES (?, ?, ?, ?, ?, ?)
[20110112 19:15:51:205 base.py:946 INFO] [122, 'k', '20100101',
'20100101', '20100101', '20100101']
[20110112 19:15:51:502 base.py:945 INFO] INSERT INTO bbb (id, name)
VALUES (?, ?)
[20110112 19:15:51:502 base.py:946 INFO] [121, 'k']
[20110112 19:15:51:531 base.py:733 INFO] ROLLBACK
Traceback (most recent call last):
File "test_trans.py", line 48, in <module>
main()
File "test_trans.py", line 39, in main
t.connection.execute(ins)
File "/prod/tools/infra/SQLAlchemy-0.5.5-py2.5.egg/sqlalchemy/engine/
base.py", line 824, in execute
return Connection.executors[c](self, object, multiparams, params)
File "/prod/tools/infra/SQLAlchemy-0.5.5-py2.5.egg/sqlalchemy/engine/
base.py", line 874, in _execute_clauseelement
return self.__execute_context(context)
File "/prod/tools/infra/SQLAlchemy-0.5.5-py2.5.egg/sqlalchemy/engine/
base.py", line 896, in __execute_context
self._cursor_execute(context.cursor, context.statement,
context.parameters[0], context=context)
File "/prod/tools/infra/SQLAlchemy-0.5.5-py2.5.egg/sqlalchemy/engine/
base.py", line 950, in _cursor_execute
self._handle_dbapi_exception(e, statement, parameters, cursor,
context)
File "/prod/tools/infra/SQLAlchemy-0.5.5-py2.5.egg/sqlalchemy/engine/
base.py", line 931, in _handle_dbapi_exception
raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
sqlalchemy.exc.IntegrityError: (IntegrityError) ('23000', "[23000]
[FreeTDS][SQL Server]Cannot insert the value NULL into column
'tt_start', table 'IAM_Equities.dbo.bbb'; column does not allow nulls.
INSERT fails. (515) (SQLExecDirectW)") u'INSERT INTO bbb (id, name)
VALUES (?, ?)' [121, 'k']
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.