Skip to content

Commit d889109

Browse files
committed
uow: possible solution for the rollback problem
* the problem is that the Session.rollback does rollback the parent too which is not the prefered situation here. * it could be that this is only necessary for the tests and not for production but that has to be tested * see https://github.com/sqlalchemy/sqlalchemy/blob/rel_2_0_36/lib/sqlalchemy/orm/session.py#L1971 * it seems that it is not configurable so the private method has to be used
1 parent cc7b450 commit d889109

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

invenio_db/uow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Copyright (C) 2024 CERN.
4+
# Copyright (C) 2024 Graz University of Technology.
45
#
56
# Invenio is free software; you can redistribute it and/or modify it
67
# under the terms of the MIT License; see LICENSE file for more details.
@@ -167,6 +168,7 @@ def __init__(self, session=None):
167168

168169
def __enter__(self):
169170
"""Entering the context."""
171+
self.session.begin_nested()
170172
return self
171173

172174
def __exit__(self, exc_type, exc_value, traceback):
@@ -199,7 +201,7 @@ def commit(self):
199201

200202
def rollback(self, exception=None):
201203
"""Rollback the database session."""
202-
self.session.rollback()
204+
self.session._transaction.rollback(_to_root=False)
203205

204206
# Run exception operations
205207
if exception:

0 commit comments

Comments
 (0)