> > ScopedSession is a class that implements __call__(). An instance of > ScopedSession then maintains a reference to a thread local object, which in > turn references individual Session objects. So if "ss" is a ScopedSession > instance, calling ss() (i.e. its __call__() method) returns the current > thread's Session. In this way ScopedSession mimics a "constructor", and an > existing application which says "sess = Session(); sess.query(Foo)" can > transparently be made to use a thread-scoped session by changing the meaning > of the identifier "Session". > > The second part of the story is that people found it tedious to say sess = > Session(); sess.query(Foo) all the time to perform an operation on the > current thread's session, so a __getattr__()-like scheme was added which > compresses those two steps into one, meaning > <some_scoped_session>.<some_Session_method>() equates to "sess = Session(); > return sess.<some_Session_method>()". But what this also means is, like the > case of __call__(), an application which currently uses a single global > Session to do everything, i.e. "session.query(Foo)" throughout, can also > transparently be made to use a thread-scoped session by changing the meaning > of the identifier "session". >
This is the best explanation I have read on this topic! Thanks for writing it! Now I clearly see what is going on. Just one more thing - when should remove() be called? (if at all) Sincerely, Peteris Krumins -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.