Skip to content

Commit

Permalink
Commit nested transactions when exiting the context
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Fedorov authored and mcfunley committed Mar 13, 2022
1 parent f9c3a5e commit 5c16c6a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pugsql/compiler.py
Expand Up @@ -3,11 +3,12 @@
"""
from . import parser, context
from .exceptions import NoConnectionError
from contextlib import contextmanager
from contextlib import contextmanager, suppress
from glob import glob
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import ResourceClosedError
import threading
import re

Expand Down Expand Up @@ -127,6 +128,9 @@ def transaction(self):
except Exception as e:
session.rollback()
raise e
else:
with suppress(ResourceClosedError):
session.commit()

def _execute(self, clause, *multiparams, **params):
if getattr(self._locals, 'session', None):
Expand Down

0 comments on commit 5c16c6a

Please sign in to comment.