title: "sqlalchemy.exc.InternalError: (psycopg2.errors.InFailedSqlTransaction) current transaction is aborted
body: <p>I wrote API using Flask-SQLAlchemy which sometimes throws error "sqlalchemy.exc.InternalError: (psycopg2.errors.InFailedSqlTransaction) current transaction is aborted, commands ignored until end of transaction block" and I'm using PostgreSQL &amp; docker containe and Ass is the sample model.
  Here is my code.</p>
  
  <pre><code>@APP.route('/get_ass_info/&lt;int:ass_id&gt;', methods=["GET"])
  def get_ass_info(ass_id):
      item = Ass.query.filter_by(main_ass_id=ass_id).first()
      ag_list = []
      if item:
          if item.sponsor != 0:
              sp_obj =Ass.query.filter_by(main_ass_id=item.sponsor).first()
              sp_name = sp_obj.name
          else:
              sp_name = 'NA'
          dob_new = datetime.datetime.strptime(str(item.dob), "%Y-%m-%d")
          today = datetime.date.today()
          age = today.year - dob_new.year
          st_obj = State.query.filter_by(id=item.ag_state).first()
          if st_obj:
              state_name = st_obj.name
              state_id = st_obj.id
              old_state_id = st_obj.old_state_id
          else:
              state_name = ''
              state_id = 0
              old_state_id = 0
          dist_obj = District.query.filter_by(id=item.ag_district).first()
          if dist_obj:
              dist_name = dist_obj.name
              dist_id = dist_obj.id
              old_dist_id = dist_obj.old_district_id
          else:
              dist_name = ''
              dist_id = 0
              old_dist_id = 0
          ass_dict = {'ass_id':item.id, 'name':item.name, 'rank': item.asslevel.name if 
                        item.agentlevel_id != None else '', 
                        'city':item.city if item.city != 'null' and item.city != None and 
                         item.city !='None' else '',
                        'mobile':item.mobile_no, 'sponsor':item.sponsor, 'state':state_name,
                        'title':item.title,'ag_state':old_state_id,'ag_district':old_dist_id}
          ag_list.append(ass_dict)
          response = jsonify(ag_list)
          response.status_code = 200
          return response
      else:
          response = jsonify(ag_list)
          response.status_code = 200
          return response
  </code></pre>
  
  <p>If anyone knows the solution then let me know.</p>