title: SQLAlchemy won't update my database
body: <p>I'm making a Pyramid app using SQLAlchemy-0.7.8. I'm using 64bit Python3.2.</p>
  
  <p>The question is, why does the following function not commit anything to the database?</p>
  
  <pre><code>def create_card(sText,sCard):
      """
      create a wildcard instance if all is well (ie,sCard match in sText)
      return 
          oCard, dCard
      otherwise return False,False
      """
      oMatch = re.search(sCard,sText)
      if oMatch:
          oCard = WildCard()
          #set up some stuff about the WildCard
  
          DBSession.add(oCard)
          DBSession.flush()
          dCard = {
                      'id'            : oCard.id,
                      'span'          : oMatch.span(),
                      'card'          : oCard.card_string,
                              }
          return oCard,dCard
      return False,False  
  </code></pre>
  
  <p>I import DBSession form another script. it is defined as follows:</p>
  
  <pre><code>DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
  </code></pre>
  
  <p>Here's some background info:</p>
  
  <p>The app I'm making is to be used to characterize large blocks of HTML through use of regular expressions. If the app gets stuck and thinks there should be a wilcard match for a piece of text then the user is given a little form to fill in. Once the form is committed create_card is called. If the wildcard is matched against the string then a WildCard instance is created.</p>
  
  <p>The WildCard class is nothing special, it just stores a string and a few integers. If I print out dCard it looks like the WildCard was sucessfully committed because it has an integer id. If I don't call flush on the database session then dCard['id'] is None.</p>
  
  <p>the id field looks like:</p>
  
  <pre><code>id = Column(Integer,Sequence('wild_seq'), primary_key=True)
  </code></pre>
  
  <p>The add and flush lines cause the following console output:</p>
  
  <pre><code>2012-09-16 12:30:34,845 INFO  [sqlalchemy.engine.base.Engine][Dummy-2] INSERT INTO wildcard_wildcards (card_string, range_id, brand_id, category_id, group_cat_map_id, heading_group_id, heading_to_grp_map_id, heading_id, value_map_id, igneore_match) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  2012-09-16 12:30:34,845 INFO  [sqlalchemy.engine.base.Engine][Dummy-2] ('sCard contents', None, None, None, None, None, None, None, None, 0)
  </code></pre>
  
  <p>So up until this point everything is behaving pretty as is expected.</p>
  
  <p>Here's the problem:
  Even though the WildCard instance looks like it has been committed to the database, and no Exceptions are raised, direct examination of the database shows that no changes are made.</p>
  
  <p>replacing flush() with commit() raises the following exception:</p>
  
  <pre><code>AssertionError: Transaction must be committed using the transaction manager
  </code></pre>