title: SQLAlchemy: session.query.one() and session.add() in one transaction
body: <p>I want to add row with <code>VALUE1</code> to table <code>TABLE1</code> only if <code>TABLE2</code> have row with <code>VALUE2</code></p>
  
  <p>I can do something like that:</p>
  
  <pre><code>session.query(TABLE2)
      .filter(TABLE2.FIELD2 == VALUE2)
      .update({TABLE2.FIELD2: VALUE2}) # without change. only for check
  session.add(TABLE1(FIELD1=VALUE1))
  session.commit()
  </code></pre>
  
  <p>But I think it is strange that I use <code>update</code> without any update.</p>
  
  <p>I want to use <code>one</code> instead of <code>update</code> but it doesn't support transactions.</p>
  
  <p>UPDATED: this solution is wrong...</p>
  
  <p>This simple solution is wrong also:</p>
  
  <pre><code>my_flag = session.query(TABLE2).filter(TABLE2.FIELD2 == VALUE2).first()
  # database can be updated here!
  if my_flag:
      session.add(TABLE1(FIELD1=VALUE1))
      session.commit()
  </code></pre>