title: SQLAlchemy idle in transaction
body: <p>I have application writen Python 3.6, Flask and SQLAlchemy (PostgreSQL).</p>
  
  <p>I encountered problems with  hanging <code>idle in transaction</code> connections in my db. It's probably because I don't commit nor rollback after select queries.</p>
  
  <p>I use default SQLALchemy configuration: <code>db = SQLAlchemy()</code></p>
  
  <p>Sample endpoint that creates hanging connections:</p>
  
  <pre><code>class Test(Resource):
  
      def get(self, pk):
          return User.query.get(pk).serialize()
  </code></pre>
  
  <p>What's the way of handling such select queries? Should I select then commit? Or select then rollback? or entirely close connection after request? But closing connection causes that on every request there will be new connection to database opened.</p>
  
  <p>What's best way?</p>