On Jul 19, 2008, at 9:10 AM, Contact 42 wrote:

>
> Hi,
>
> I am using sa 0.5b2 under python 2.5.
>
> Should the following code commit myobj.
>
> engine = create_engine(appconfig.dburi, strategy='threadlocal')
> Session = scoped_session(sessionmaker(bind=engine, autoflush=True,
> autocommit=True))
>
> sess = Session()
> engine.begin()
> sess.add(myobj)
> engine.commit()
>
> I am noticing that it does not. However, if I do
>
> sess = Session()
> sess.begin()
> sess.add(myobj)
> sess.commit()
>
> it works.
>
> Am I missing something ?

The "commit()" method on Session has the additional functionality of  
flushing itself when called.  If you want to use Session within a  
threadlocal transaction at the engine level, you'd have to ensure that  
you flush() the session manually before commit.

These days the Session has become more prominent as the center of  
transactional control, however, so you might find it easier to just go  
through scoped_session() for transaction control entirely.   Session  
has an execute() and connection() method for issuing raw SQL too.   If  
you continue to use the threadlocal engine strategy, then implicit  
executions (i.e. somestatement.execute()) should participate in the  
same transaction as the Session.

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