On Feb 9, 2011, at 12:01 PM, Brent McConnell wrote: > I'm having issues with the sqlalchemy session and completely realize this is > from my own lack of understanding but can't seem to find a solution. My plan > was to create a library with functions like so... > > def func1 (id, session=None): > result = <do somework> > session.add(something) > return result > > def func2 (id, session=None): > result = <do somework> > session.add(something) > return result > > then from someplace else use the functions like so... > > session = scoped_session() > result = func1(1, session) > result2=func2(2, session) > session.commit() > session.close() > > This doesn't work though. Do I need to return the session for something like > this to work? Any advice on the correct pattern to use when trying to create > a transaction across several functions?
Looks fine to me. "doesn't work" doesn't carry a lot of detail. I'd note that the purpose of scoped_session() is so that "session" is safe to use as a global variable, though there's no reason you can't pass it explicitly to functions as well. -- 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.
