On 5/26/15 7:26 AM, David Allouche wrote:
On 26 May 2015, at 09:16, Burak Arslan <[email protected]> wrote:

same here but before passing the model instance from controller to view,
all instances are detached from session (via expunge()). this 1)
prevents a lot of unexpected db queries. 2) lets you recycle db
connections as soon as possible.
Oh, that's clever.

One of the shortcomings of SQLAlchemy is that it makes it easy to produce a "query 
within a loop" anti-pattern through relation traversal. So far I prevented this by 
avoiding loading mapped objects as much as possible, instead loading only specific 
columns — with the nice side effect of reducing data transfer with the database.

Now, thanks to you I realise I can prevent the anti-pattern with less code 
using Session.expunge_all().

why don't you just .close() the session entirely and release the transaction / connection as well ?





--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to