OK not totally clear what your code actually says because your second
example does not illustrate where this ".remove()" is present.
>
> Even in this type of program, is it better to always call Session.remove()
> and get new Session object for each unit of work?
calling .remove() has the advantage that any error state within the
Session will definitely be gone. The Session tries to be recoverable
from any error scenario if it is fully rolled back, but there could
still be objects inside of it with problems, hence .close() solves
that. Then, in even fewer cases, the Session might still be in a
broken state (due to undiscovered SQLAlchemy bugs for example), so
.remove() makes sure those are gone too.
So, not critical to call .close() or .remove() but it gives you extra
levels of resilience against failure modes that are not well covered.
If you are only running session.execute() and not working with
objects, it probably doesn't make any difference.
> I'm trying to see if there's a down side of using same Session for life time
> of application.
>
>
> Thanks.
> Sam
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
>
http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See
http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
sqlalchemy+...@googlegroups.com.
> To post to this group, send email to
sqlal...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/sqlalchemy.
> For more options, visit
https://groups.google.com/d/optout.