title: Flask session member not persisting across requests
body: <p>I'm writing a quick app to view a giant XML file with some AJAX style calls to <code>viewgroup</code>. My problem is <code>session['groups']</code> not persisting. I have some old array with only 4 members that is stuck somewhere (cookie?..). That value is present when <code>view</code> is called. I then overwrite that session member with info from the recently opened xml file that contains 20+ members. </p>
  
  <p>However, when <code>viewgroup</code> is called the session variable has reverted to the old value with only 4 members in the array! </p>
  
  <p>Code followed by output. Note the 3 <code>sessionStatus()</code> calls</p>
  
  <pre><code>def sessionStatus():
      print "# of groups in session = " + str(len(session['groups']))
  
  @app.route('/')
  def index():
      cams = [file for file in os.listdir('xml/') if file.lower().endswith('xml')]
      return render_template('index.html', cam_files=cams)
  
  @app.route('/view/&lt;xmlfile&gt;')
  def view(xmlfile):
      path = 'xml/' + secure_filename(xmlfile)
      print 'opening ' + path
      xmlf = open(path, 'r')
      tree = etree.parse(xmlf)
      root = tree.getroot()
      p = re.compile(r'Group')
      groups = []
      for g in root:
          if (p.search(g.tag) is not None) and (g.attrib['Comment'] != 'Root'):
              groups.append(Group(g.attrib['Comment']))
      sessionStatus()
      session['groups'] = groups
      sessionStatus()
      return render_template('view.html', xml=xmlfile, groups=groups)
  
  @app.route('/viewgroup/&lt;name&gt;')
  def viewGroup(name):
      groups = session['groups']
      sessionStatus()        
      if groups is None or len(groups) == 0:
          raise Exception('invalid group name')
      groups_filtered = [g for g in groups if g.name == name]
      if len(groups_filtered) != 1:
          raise Exception('invalid group name', groups_filtered)
      group = groups_filtered[0]
      prop_names = [p.name for p in group.properties]
      return prop_names
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>opening xml/d.xml
  # of groups in session = 5
  # of groups in session = 57
  127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /view/d.xml HTTP/1.1" 200 -
  127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/ivtl.css HTTP/1.1" 304 -
  127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/jquery.js HTTP/1.1" 304 -
  127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/raphael-min.js HTTP/1.1" 304 -
  127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/ivtl.css HTTP/1.1" 304 -
  127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /favicon.ico HTTP/1.1" 404 -
  # of groups in session = 5
  127.0.0.1 - - [17/Aug/2011 17:27:31] "GET /viewgroup/DeviceInformation HTTP/1.1" 200 -
  </code></pre>
  
  <p>I need all 57 groups to stay around. Any hints?</p>