• Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibite

    From Jon Ribbens@21:1/5 to Lawrence D'Oliveiro on Wed Sep 11 21:12:01 2024
    On 2024-09-11, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
    On Tue, 10 Sep 2024 22:48:36 -0000 (UTC), Jon Ribbens wrote:
    But what if you tell it the wrong thing ...

    To get back to the original point of this thread, all that rigmarole to
    try to ensure to call “rollback” in case of an exception is completely unnecessary: the DBMS will take care of that for you.

    No, it won't.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Jon Ribbens on Wed Sep 11 20:30:56 2024
    On Tue, 10 Sep 2024 22:48:36 -0000 (UTC), Jon Ribbens wrote:

    But what if you tell it the wrong thing ...

    To get back to the original point of this thread, all that rigmarole to
    try to ensure to call “rollback” in case of an exception is completely unnecessary: the DBMS will take care of that for you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Greg Ewing on Thu Sep 12 23:10:05 2024
    On Sun, 8 Sep 2024 12:48:50 +1200, Greg Ewing wrote:

    This is how I normally do things like this:

    try:
    do something .commit()
    except:
    log something .rollback()

    Doing an explicit rollback ensures that the transaction is always rolled
    back if it is interrupted for any reason.

    Don’t bother. Let the DBMS deal with that for you. That’s what it’s for.

    Also, maybe you meant “finally” instead of “except”?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)