Hi, thanks for joining us here. :)
Yes, zope.transaction does indeed support savepoints:
somesavepoint = transaction.savepoint()
And indeed I can see it being emitted in the SQL debug output:
2011-11-13 15:59:57,895 INFO [sqlalchemy.engine.base.Engine][worker 0]
SAVEPOINT sa_savepoint_1
2011-11-13 15:59:57,896 INFO [sqlalchemy.engine.base.Engine][worker 0] {}
2011-11-13 15:59:57,896 INFO [sqlalchemy.engine.base.Engine][worker 0]
INSERT INTO user_stats (user_id, tstamp, portal, ads_new, ads_modified)
VALUES (%(user_id)s, %(tstamp)s, %(portal)s, %(ads_new)s, %(ads_modified)s)
2011-11-13 15:59:57,897 INFO [sqlalchemy.engine.base.Engine][worker 0]
{'ads_modified': 0, 'user_id': 1, 'ads_new': 0, 'portal': 'XXXXXX',
'tstamp': datetime.date(2011, 11, 13)}
2011-11-13 15:59:57,898 INFO [sqlalchemy.engine.base.Engine][worker 0]
ROLLBACK TO SAVEPOINT sa_savepoint_1
2011-11-13 15:59:57,898 INFO [sqlalchemy.engine.base.Engine][worker 0] {}
2011-11-13 15:59:57,904 INFO [sqlalchemy.engine.base.Engine][worker 0]
BEGIN (implicit)
2011-11-13 15:59:58,100 ERROR [pyramid_debugtoolbar][worker 0] Exception
at http://localhost:6543/ads/view/28328?category=
The exception thrown in the last line is
TransactionFailedError: An operation previously failed, with traceback
And the traceback ends with:
IntegrityError: (IntegrityError) duplicate key value violates unique
constraint "user_stats_pkey"
Stemming from the transaction.commit() I manually issue in order to
match (in number) against savepoints issued. Even if I remove it
manually, it will still be called (and cause the exception) by the
transaction middleware outside of the request handler.
But that IntegrityError has been caught (right when the ROLLBACK is
issued above). Also the ROLLBACK is apparently done automatically by
zope.transaction because if I try it manually:
savepoint.rollback()
I get InvalidSavepointRollbackError
I tried pretty much every combo of with and without savepoints, manual
or automatic flushin, commits, rollbacks and aborts, I just can't get
the request to complete without any exceptions.
.oO V Oo.
On 11/13/2011 06:23 PM, mike bayer wrote:
Hi !
Was just talking to Vlad over on the SQLAlchemy list. What is needed
in this case is the ability to use SQLAlchemy's "begin_nested()"
method, which emits a "SAVEPOINT" instruction against the relational
database. When using this feature, the next call to rollback(),
assuming the "nested" status is still in progress, will "ROLLBACK TO
SAVEPOINT". My understanding is that we just need to know how to use
this feature when using the zope.transaction extension to manage
transactions. In particular, if zope.transaction intercepts calls to
"Session.rollback" and prevents them, it needs to either provide its
own means of managing a "nested" SQLAlchemy transaction, or needs to
recognize SQLAlchemy rollback() calls that are in fact against a
"nested" transaction, which would be via some further introspection on
the SQLAlchemy session when the event is intercepted.
At some point I'll have the opportunity to work with zope.transaction
firsthand and then we'll no longer need to educate zzzeek about such
things. Until then please bear with me !
--
You received this message because you are subscribed to the Google
Groups "pylons-discuss" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pylons-discuss/-/Jmji6_ohyCYJ.
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/pylons-discuss?hl=en.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.