title: Python-mysql: when to explicitly rollback a transaction
body: <p>Suppose, I have a modifying statement:</p>
  
  <pre><code>cursor = conn.cursor()
  # some code
  affected_rows1 = cursor.execute(update_statement1, params1)
  # some code
  conn.commit()
  cursor.close()
  </code></pre>
  
  <p><strong>Should I wrap the block of code with a <code>try ... except</code> and explicitly rollback a transaction when an exception is raised, and which MySQLdb exceptions should I catch to rollback?</strong> I used to catch any <code>StandardError</code> in this case, but now I have a hesitation that the block of code would even need an explicit rollback at all. </p>
  
  <p>The following example is slightly more difficult, and I understand that it does require an explicit rollback if the first update statement succeeded. Still, which exceptions should I catch in this case:</p>
  
  <pre><code>cursor = conn.cursor()
  # some code
  affected_rows1 = cursor.execute(update_statement1, params1)
  # some code
  affected_rows2 = cursor.execute(update_statement2, params2)
  #some code
  conn.commit()
  cursor.close()
  </code></pre>