On Sat, May 23, 2009 at 02:43:33PM -0400, Michael Bayer wrote:
> 
> 
> On May 23, 2009, at 10:15 AM, Alessandro Dentella wrote:
> 
> >
> > Hi,
> >
> >  when from my pygtk application i commit, I really do::
> >
> >            if self.session.autocommit:
> >                self.session.begin()
> >
> >            self.session.commit()
> >
> >  I'm normally using session.autocommit = True as a mean to prevent all
> >  those 'idle in transaction' processes (that prevent me from  
> > changing the
> >  structure of the database - I use PostgreSQL).
> > moreover I use
> >  autoflush=False to prevent flushing objects when I just need to ge  
> > more
> >  info from the database via normal 'select'.
> >
> >  Everything seems to work nicely apart the fact that using this  
> > along with
> >  after_commit hook in SessionExtension, turns out in a double call  
> > of the
> >  hook. The first when I run session.begin() and the second when I run
> >  session.commit().
> 
> I can't see how that occurs.  Can you please post a stack trace ? 
>    


The following code demostrates what I mean: the after_commit hook is called
twice, the first time is called after sess.begin() and the second anfter
sess.commit(), the output:

   BEGIN
   Whithin SessionExtension 'after_commit'
   COMMIT
   Whithin SessionExtension 'after_commit'


Thanks fo your attention

sandro
*:-)

------------------------------------------------------------
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, ForeignKey, text, func
from sqlalchemy.orm import sessionmaker, mapper, relation
from sqlalchemy.orm.interfaces import SessionExtension
from sqlalchemy.types import *

Base = declarative_base()
Base.metadata.bind = 'sqlite://'

class SKSessionExtension(SessionExtension):

    def after_commit(self, session):
        print "Whithin SessionExtension 'after_commit'"
        

Session = sessionmaker(bind=Base.metadata.bind,
                       expire_on_commit=True,
                       autoflush=False,
                       autocommit=True,
                       extension=SKSessionExtension(),
                       )
sess = Session()

class Status(Base):
     __tablename__ = 'ticket_status'
     id = Column(Integer, primary_key=True)
     status = Column(String(20))

Base.metadata.create_all()

s = Status()
s.status = "test"
sess.add(s)

print "BEGIN"
sess.begin()
print "COMMIT"
sess.commit()

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to