On May 30, 2009, at 1:56 AM, ericthompso...@gmail.com wrote:

> Upon reaching the instantiation of Foo, my code blows up with the
> error message in the subject.  Now I realize this is often caused by
> threading issues - multiple threads, each with their own Session,
> trying to touch an entity without first merging that entity into the
> thread's local session.  But my application is single-threaded and to
> the best of my knowledge I'm not creating any new sessions other than
> the ScopedSession that was created when I imported elixir.  Even if I
> had attempted to create several sessions via elixir_session(), my
> understanding is that I would have been returned the same session
> because I haven't changed threads and elixir by default uses a
> ScopedSession.

that is all correct.

> So why is Foo winding up in a new session (and how did
> it already get attached to my current session)?   I haven't passed any
> options regarding the session in my entity definitions.

I can't see anything here which would cause this.    A frequent cause  
of this confusion is when a library makes use of the  
ScopedSession.mapper method which has the effect of objects being  
automatically added to a session without the need to say  
session.add(object) - but again confusion would only occur here if  
there is more han one session in use.

> On a somewhat related note, why does Session have so many class
> methods? It's perplexing to me that I can do things like
> elixir_session.query(Foo).all() and also elixir_session().query
> (Foo).all().  I've tried digging through Elixir's entity.py and
> SQLAlchemy's session.py but I didn't get much out of my first couple
> of reads.

its the ScopedSession you're dealing with.    The methods are not  
class methods, as ScopedSession is instantiated.   for every public  
Session method, the ScopedSession implements a proxying method which  
will invoke that method upon a Session pulled from a threading.local()  
object.   To access the Session stored in the threading.local()  
directly, ScopedSession implements __call__().



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to