I'm not sure what the "right" setting for autocommit is. I'd prefer to
leave it off, because database updates make more sense to me with
session.commit() calls. Modify anything locally you want to change,
then call commit():

    some_model.name = "John"
    some_model.zip = "11201"
    session.commit()

The problem is with queries. If I have this code in multiple places:

    user = Session().query(User).get(userid)

My understanding is each call leaves a database connection hanging
around forever. So I have bunch of this in my code:

    session = Session()
    user = session.query(User).get(userid)
    session.close()

I also understand (maybe I'm wrong?) that using autocommit=True would
fix that, so I could just query away and not have to close sessions.

But with autocommit=True my first example would need a flush() instead
of a commit() to save. Or I could do a session.begin(), but for single
attribute updates that's a waste.

It's all so confusing, it's like there's two different sets of
documentation for autocommit being on or off.

What would be ideal is if I could just query without having to close
sessions, perhaps with a class method on Session? There isn't one
unfortunately (I'm not using scoped_session, just regular session.)
What if there was a:

    user = Session.query(User).get(userid)

That cleans up after itself. Then I could have autocommit=False and
all would be well.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en.

Reply via email to