I found this:
http://www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual_creating
which I see is almost what Elixir is doing. The important part I
missed was the mandatory session.remove() at the end of all the
request handlers, otherwise old data will be returned. I guess is what
I was seeing (and seems to fix my problem). I think it would be
worthwhile to put that in the Elixir docs somewhere.
Also, relatedly Elixir currently does:
from sqlalchemy.orm import scoped_session
session = scoped_session(sqlalchemy.orm.create_session)
but I'd like transactional=True, ie.
from sqlalchemy.orm import scoped_session, sessionmaker
Session = scoped_session(sessionmaker(autoflush=True, transactional=True))
I'm doing this now:
import elixir
from sqlalchemy.orm import scoped_session, sessionmaker
elixir.session = scoped_session(sessionmaker(autoflush=True,
transactional=True))
from elixir import *
...
Is doing this sensible or is there a cleaner way to tell Elixir instead?
thanks,
scott
On Jan 17, 2008 1:24 PM, Scott Graham <[EMAIL PROTECTED]> wrote:
> Hi
>
> I'm having a little trouble understanding sessions when using Elixir
> inside of CherryPy (web server).
>
> When I create/delete objects using session.save(obj) or
> session.delete(obj) followed by session.flush() and then go back to a
> "view" page, I'm "sometimes" seeing deleted objects still showing up
> or newly created ones will be missing. I'm guessing this is some sort
> of threading issue. (?)
>
> I've tried fiddling with using session.begin(), session.commit(),
> metadata.bind.autoflush=True/False, session.refresh/expire but I'm
> quite confused.
>
> I found this http://tools.cherrypy.org/wiki/Databases which I thought
> might be relevant, but then
> http://elixir.ematia.de/trac/wiki/TutorialDivingIn#a8.Moreonsessions
> says that the session should already be thread-local.
>
> So, should I be creating my own sessions inside of each web-request
> handler? If so, how can I attach those to my Elixir objects? If not,
> how do I make sure that the global elixir.session in all the threads
> gets a consistent view of the database?
>
> thanks,
> scott
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---