Skip to content

Commit

Permalink
uow: possible solution for the rollback problem
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
utnapischtim committed Nov 12, 2024
1 parent cc7b450 commit d889109
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion invenio_db/uow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -167,6 +168,7 @@ def __init__(self, session=None):

def __enter__(self):
"""Entering the context."""
self.session.begin_nested()
return self

def __exit__(self, exc_type, exc_value, traceback):
Expand Down Expand Up @@ -199,7 +201,7 @@ def commit(self):

def rollback(self, exception=None):
"""Rollback the database session."""
self.session.rollback()
self.session._transaction.rollback(_to_root=False)

# Run exception operations
if exception:
Expand Down

0 comments on commit d889109

Please sign in to comment.