title: Issues with scoped_session in sqlalchemy - how does it work?
body: <p>I'm not really sure how scoped_session works, other than it seems to be a wrapper that hides several real sessions, keeping them separate for different requests. Does it do this with thread locals?</p>
  
  <p>Anyway the trouble is as follows:</p>
  
  <pre><code>S = elixir.session # = scoped_session(...)
  f = Foo(bar=1)
  S.add(f) # ERROR, f is already attached to session (different session)
  </code></pre>
  
  <p>Not sure how f ended up in a different session, I've not had problems with that before. Elsewhere I have code that looks just like that, but actually works. As you can imagine I find that very confusing.</p>
  
  <p>I just don't know anything here, f seems to be magically added to a session in the constructor, but I don't seem to have any references to the session it uses. Why would it end up in a different session? How can I get it to end up in the right session? How does this scoped_session thing work anyway? It just seems to work sometimes, and other times it just doesn't.</p>
  
  <p>I'm definitely very confused.</p>