title: Python sqlalchemy TypeError when trying to iterate through .all() query
body: <p>I have a python BaseHTTPServer, that returns a list of restaurants via a .all() query. It works fine on the first run, but after an update I get</p>
  
  <pre><code>Exception happened during processing of request from ('10.0.2.2', 49927)
  Traceback (most recent call last):
    File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
      self.process_request(request, client_address)
    File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
      self.finish_request(request, client_address)
    File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
      self.RequestHandlerClass(request, client_address, self)
    File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
      self.handle()
    File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
      self.handle_one_request()
    File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
      method()
    File "webserver.py", line 43, in do_GET
      allRestaurants = session.query(Restaurant).all()
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2703, in all
      return list(self)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2855, in __iter__
      return self._execute_and_instances(context)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2876, in _execute_and_instances
      close_with_result=True)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2885, in _get_bind_args
      **kw
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2867, in _connection_from_session
      conn = self.session.connection(**kw)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 966, in connection
      execution_options=execution_options)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 971, in _connection_for_bind
      engine, execution_options)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 382, in _connection_for_bind
      self._assert_active()
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 276, in _assert_active
      % self._rollback_exception
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/exc.py", line 258, in __str__
      details.append("[parameters: %r]" % params_repr)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/util.py", line 368, in __repr__
      return self._repr_multi(self.params, typ)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/util.py", line 386, in _repr_multi
      for params in multi_params)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/util.py", line 386, in &lt;genexpr&gt;
      for params in multi_params)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/util.py", line 412, in _repr_params
      ", ".join(trunc(value) for value in params)
  TypeError: 'int' object is not iterable
  </code></pre>
  
  <p>Is the .all() query returning an int Instead of a list? 
  Or is this some internal error with one part of sqlalchemy passing another part an int instead of something iterable?
  It's way beyond my expertise to debug a library, so I'm just scratching my head.
  Please help.
  Here is an abbreviated version of my webserver file:</p>
  
  <pre><code>from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
  import cgi
  from sqlalchemy import create_engine
  from sqlalchemy.orm import sessionmaker
  from database_setup import Base, Restaurant, MenuItem
  
  # Database setup on webserver load instead of pageload
  dbpath = 'sqlite:///restaurantmenu.db'
  engine = create_engine(dbpath)
  Base.metadata.bind = engine
  DBSession = sessionmaker(bind = engine)
  session = DBSession()
  restaurants = session.query(Restaurant)
  assert(type(restaurants) != "int")
  
  
  class webServerHandler(BaseHTTPRequestHandler):
  
      def do_GET(self):
          try:
  
              if self.path.endswith("/restaurants"):
                  self.send_response(200)
                  self.send_header('Content-type', 'text/html')
                  self.end_headers()
                  output = ""
                  output += "&lt;html&gt;&lt;body&gt;"
                  assert(type(restaurants) != "int"), "type has changed."
  
                  session.flush()
                  allRestaurants = session.query(Restaurant).all()
                  for restaurant in allRestaurants:
                      output += "&lt;h1&gt;" + restaurant.name + "&lt;/h1&gt;"
                      output += '''&lt;a href="http://localhost:8080/restaurants/''' + repr(restaurant.id) + '''/edit"&gt;Edit&lt;/a&gt;'''
                      output += '''&lt;a href="http://localhost:8080/restaurants/''' + repr(restaurant.id) + '''/delete"&gt;Delete&lt;/a&gt;'''
  
  
                  output += "&lt;/body&gt;&lt;/html&gt;"
                  self.wfile.write(output)
                  print(output)
                  return
  
              if self.path.endswith("/edit"):
                  self.send_response(200)
                  self.send_header('Content-type', 'text/html')
                  self.end_headers()
                  id = int(self.path.split('/')[-2])
                  restaurant = restaurants.filter_by(id = id).one()
                  output = ""
                  output += "&lt;html&gt;&lt;body&gt;"
                  output += "&lt;h1&gt;" + restaurant.name + "&lt;/h1&gt;"
                  output += '''&lt;form method='POST' enctype='multipart/form-data' action='/restaurants/''' + repr(restaurant.id) + '''/edit'&gt;&lt;h2&gt;Please rename the restaurant&lt;/h2&gt;&lt;input name="message" type="text" &gt;&lt;input type="submit" value="Submit"&gt; &lt;/form&gt;'''
                  output += "&lt;/body&gt;&lt;/html&gt;"
                  self.wfile.write(output)
                  print(output)
                  return       
  
          except IOError:
              self.send_error(404, 'File Not Found: %s' % self.path)
  
      def do_POST(self):
          try:
              self.send_response(301)
              self.send_header('Content-type', 'text/html')
              self.end_headers()
              ctype, pdict = cgi.parse_header(
                  self.headers.getheader('content-type'))
              if ctype == 'multipart/form-data':
                  fields = cgi.parse_multipart(self.rfile, pdict)
                  formName = self.headers.getheader('name')
                  print(fields)
                  print(self.path)
                  messagecontent = fields.get('message')
                  id = int(self.path.split('/')[-2])
                  restaurant = restaurants.get(id)
                  restaurant.name = messagecontent
                  session.add(restaurant)
                  session.commit()
                  DBSession = sessionmaker(bind = engine)
                  session = DBSession()
                  assert (restaurants.filter_by(id = id).one().name == messagecontent), "Database update failure"
  
              output = ""
              output += "&lt;html&gt;&lt;body&gt;"
              output += " &lt;h2&gt; Restaurant renamed: &lt;/h2&gt;"
              output += "&lt;h1&gt; %s &lt;/h1&gt;" % messagecontent[0]
              output += '''&lt;form method='POST' enctype='multipart/form-data' action='/hello'&gt;&lt;h2&gt;What would you like me to say?&lt;/h2&gt;&lt;input name="message" type="text" &gt;&lt;input type="submit" value="Submit"&gt; &lt;/form&gt;'''
              output += "&lt;/body&gt;&lt;/html&gt;"
              self.wfile.write(output)
              print(output)
          except:
              pass
  </code></pre>
  
  <p>UPDATE - I added DBSession = sessionmaker(bind = engine) and session = DBSession() after the database commit and now have a InterfaceError: unprintable InterfaceError object</p>