I've been beating my head over this one. I read the ORM Creating a
Thread-local Context doc and the web but don't see a simple
answer...saw some old SA/Cherrypy code that used cherrypy 'tools' etc.
The SA doc seems straightforward but I keep getting
sqlalchemy.exc.UnboundExecutionError errors.
My in my cherrypy application startup code I do:
engine = create_engine('mysql://xxxxxxxx@localhost/test', echo=True)
Session = scoped_session(sessionmaker(bind=engine))
...
create cherrypy root object and sit and wait for a request
In my request handler (REST type)
I call:
fld = ProjectORM
session = Session()
session.query(ProjectORM).filter(ProjectORM == 12).one()
....
When I issue a request that goes through the above 3 lines
I get a:
UnboundExecutionError: Could not locate a bind configured on mapper
Mapper|ProjectORM|project, SQL expression or this Session
If I move that same 3 lines of code to the application startup just
after the creation of the Session factory it works.
I'm assuming it works there because it is on the main thread.
I thought (incorrectly?) that using the scoped_session() wrapping
would then allow later thread code to get a session object that would
be tied to the thread.
Any help would be appreciated.
John
--
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.