Foreword: sqlalchemy is really amazing!

Hello,

I'm trying to build a database where users become aware of what has been 
changed by other users: there is a SessionExtension that collects info about 
changes and then dispatch some messages with a Pyro Event Server.

I'm trying to understand what can be my link point between flush, commit and 
rollback operations to store the single IDs into a per-transaction dictionary 
and then, when there is a commit on a non-nested transaction, gather all and 
dispatch the message through Pyro

I thought I could use id(session.transaction) as a dictionary key, but 
- it changes between before_flush and after_flush
- remains the same between before_flush, after_commit and rollback

I need to gather IDs in after_commit because theID is a serial Postgres value 
that is available only after flush()

The only correct "link" I found it in an obscure (to me) 
_SessionTransaction__parent, so I suspect this is not the "correct" way to 
get to my goal. Is there a cleaner way to do such a thing?

Thanks in advance, here is some code:

in mySessionExtension I put:
    def after_rollback(self, session):
        print "after_rollback", id(session.transaction)

    def after_commit(self, session):
        print "after_commit", id(session.transaction)
    
    def before_flush(self, session, flush_context, objects):
        print "before_flush", id(session.transaction)
    
    def after_flush(self, session, flush_context):
        print "after_flush", id(session.transaction), 
id(session.transaction._SessionTransaction__parent)

In the main I made:

    ss.begin()
    rep = dict((x.codice, x) for x in mappers.Reparto.query.all())
    r = rep['3']
    r.descrizione += '!'
    ss.flush()
    if 1:
        ss.begin_nested()
        r = rep['2']
        r.descrizione += '!'
        ss.flush()
        ss.rollback()
    ss.commit()

The resulting dump was
before_flush 147722732
after_flush 149425612 147722732
before_flush 149423788
after_flush 149489964 149423788
after_rollback 149423788
after_commit 147722732

I'm working with Python 2.5, SQA 0.4.1 with scoped_session 
(transactional=False, autoflush=False)

Thanks

-- 
Cordialmente

Stefano Bartaletti
Responsabile Software

G.Tosi Spa Tintoria

Skype account: stefano.bartaletti
ICQ contact  : 1271960

Viale dell'Industria 61
21052 Busto Arsizio (VA)

Tel. +39 0331 34 48 11
Fax  +39 0331 35 21 23 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to