title: python / mysql - Transactions / Rollback not working
body: <p>First time using Transactions in MySQL</p>
  
  <p>python 3.5.2</p>
  
  <p>MySQL 5.7.16</p>
  
  <p>SQL Alchemy </p>
  
  <p>I have looked at other questions/examples but cannot figure out why the below code does not function as expected for me. </p>
  
  <p>The second INSERT statement fails (intentionally for this example) and the exception handler should execute ROLLBACK. I would expect/desire the first INSERT statement to be removed from the database but it is still present.</p>
  
  <p>Please could someone provide me with the correct solution. </p>
  
  <pre><code>def transaction():
  
      conn.execute("SET autocommit = 0;")
      conn.execute("START TRANSACTION")
  
      try:
          conn.execute("""INSERT INTO ....""")
          conn.execute("""INSERT INTO .....""") # this one fails 
      except:
          conn.execute("ROLLBACK")
          logging.warning('Exception SQL')
      else:
          conn.execute("COMMIT")
  </code></pre>