My guess is that you could do new.refresh()
before returning the object out of get_new new will be detached from the session (I think, maybe you have to detach it explicitly before closing the session), but its id attribute will be set in the object On Aug 14, 5:28 pm, Michael Hipp <[email protected]> wrote: > I'm obviously missing some key concept as regards the management of sessions. > This seemingly simple usage fails: > > def get_new(): > sess = Session() > new = Something() # new orm object > sess.add(new) > sess.commit() > sess.close() > return new > > new = get_new() # request a new Something > print new > print new.id > > Those last 2 print lines throw: > > DetachedInstanceError: Instance <Something at 0x2873ed0> is not bound to > a Session; attribute refresh operation cannot proceed > > I seem to keep butting heads with the session needing to be a global eternal > thing (opposite what the docs recommend). I could create another session and > add 'new' to it, but that seems like a lot of boilerplate when all I wanted to > do was get a bit of info from the returned object. > > Can someone explain how this is supposed to be done? > > Thanks, > Michael -- 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.
