<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Aug 8, 2014 at 4:38 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor <<a href="mailto:ckaynor@zindagigames.com">ckaynor@zindagigames.com</a>> wrote:<br>


> However, I'd recommend re-raising the exception after rolling back the<br>
> transaction with a bare "raise" statement right after the db.rollback() - at<br>
> the absolute minimum, you should log the error. This will likely let you see<br>
> what your problem is.<br>
<br>
</div>AIUI, aborting the process with an uncaught exception would roll back<br>
implicitly, so there's no need to "bare except, roll back, bare<br>
raise". But even if that's not the case, I would be looking at a<br>
try/finally for this, rather than a try/except/raise.<br></blockquote><div><br></div><div>I would imagine that on connection close, the server would rollback any uncommitted transactions, however that presumes that the connection close is completed in a reasonably timely manner (with a try...finally for closing, it should be).</div>

<div><br></div><div>This is one case where I think try...except/raise is better than try...finally. If you use try...finally to rollback, you'd have to either track whether you committed, or you'd rollback with no actions (or possibly a committed action, which could have odd behavior, depending on the implementation)</div>

<div><br></div><div>try:</div><div>    action</div><div>    commit</div><div>except:</div><div>    rollback</div><div>    raise</div><div><br></div><div>I feel is better than:</div><div><br></div><div>try:</div><div>    action</div>

<div>    commit</div><div>finally:</div><div>    rollback</div><div><br></div><div>or:</div><div><br></div><div>success = False</div><div>try:</div><div>    action</div><div>    commit</div><div>    success = True</div><div>

finally:</div><div>    if success:</div><div>        rollback</div><div><br></div><div>and is very different than:</div><div><br></div><div>try:</div><div>    action</div><div>finally:</div><div>    commit</div></div></div>

</div>