On 9/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]
> wrote:
Here is a small, exemplary snippet of code to show you how to create
and save objects without threadlocal magic in SQLAlchemy:
---------------------- snipp -------------------
page = WikiPage(name='PylonsForRunaways')
session.save(page) # save page to session
session.flush () # write session changes to the database
---------------------- snipp -------------------
I kind of discovered this myself when going through the SQLAlchemy docs. I dislike the extra lines of code in every controller. Maybe there's a way to get threadlocal-like functionality in Python 2.5 by wrapping the Controller method invocation in a 'with' block that does the setup and teardown and only have to add the "session.save(page)" stuff or, even better, discovering which objects were instantiated.
In the worst case it would probably be possible to create a common parent class that would catch the instantiations and provide them via a singleton to the Controller invocation wrapper. But I haven't looked at it too closely.
I did run into problems even with SessionContext in my threaded app. It seemed like I needed to re-fetch all of the pertinent objects from the new thread; I got exceptions saying the objects were associated with the wrong context otherwise. I'm sure it's covered in the SQLAlchemy docs, which I've been skimming more than closely reading.
--
Daniel
http://www.storytotell.org -- Tell It!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss
-~----------~----~----~----~------~----~------~--~---
