Made some more progress and I probably need to share this with the TG
group. The problem I showed below went a way and I'm not sure why?
Coded just like below, it works now. I guess maybe a complete kill of
TG did it. The next part probably belongs more on the TG list, but I'd
like to share it here because the metadata portion is applicable.
I found that I had to reconnect a DynamicMetaData instance to an engine
if I wanted to use it. That was a pain, and I figured since I'm using
threadlocal I need each spawned thread to connect upon initialization.
And here is a solution:
engine = sqlalchemy.create_engine(cns)
def connectKlass(thread_index):
for klass in (Tinwsys, User, Project):
class_mapper(klass).mapped_table.metadata.connect(engine)
cherrypy.server.on_start_thread_list.append(connectKlass)
class PlanReviewController(controllers.RootController, RESTfulController):
....
This makes sure each thread makes a connection. Again, this is probably
more fit for the TG group, but it was the understanding of threadlocal
and metadata connections that I have been grasping for and finally got.
Particularly that in a threadlocal context, engines are bound to
metadata, not sessions. Do I understand that correctly?
Randall
Randall Smith wrote:
> This is insane. I chose a case I was confident would work and I still
> have the same problem. Check it out:
>
> def save(self, project, **data):
> pid = int(project.id)
> engine = sqlalchemy.create_engine(cns)
> print engine, '...................'
> session = sqlalchemy.create_session(bind_to=engine)
> print session, '....................'
> project = session.query(Project).get(pid)
> print project.title, '...................................'
> session.flush()
> print project.title, '...................................'
> session.refresh(project)
> print project.title, '...................................'
> tg.flash("Changes saved!")
> raise tg.redirect("/")
>
> Look at the output now:
>
> <sqlalchemy.engine.threadlocal.TLEngine object at 0xb71d8f2c>
> ...................
> <sqlalchemy.orm.session.Session object at 0xb71d8cac> ....................
> Test Project 2 ...................................
> Title ...................................
> Test Project 2 ...................................
>
> Again, I can't help that this is in a threadlocal context, but it makes
> no sense to me why the changes are not saved to the database. The last
> line should read:
>
> Title ..............................
>
> Randall
>
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users