From f87f20cb2705d092dc29e58e4ba4c06619cf9bdd Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Fri, 6 Nov 2026 23:55:12 +0800 Subject: [PATCH] fix: commit the bulk ACE deletion in the repository delete_all_ace_starting_with_path was the only RBAC write method without a commit. The request session is only closed at teardown, so the deletion was rolled back and the ACEs came back on the next snapshot reload. Tests did not catch it because they share one session for the whole class. --- gns3server/db/repositories/rbac.py | 1 + tests/controller/test_rbac.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/gns3server/db/repositories/rbac.py b/gns3server/db/repositories/rbac.py index 8fa8c7c73..4ab7af2c7 100644 --- a/gns3server/db/repositories/rbac.py +++ b/gns3server/db/repositories/rbac.py @@ -295,6 +295,7 @@ class RbacRepository(BaseRepository): query = delete(models.ACE).where(models.ACE.path.startswith(path)).execution_options(synchronize_session=False) result = await self._db_session.execute(query) + await self._db_session.commit() self._rbac_state.mark_dirty() log.debug(f"{cast(CursorResult, result).rowcount} ACE(s) have been deleted") diff --git a/tests/controller/test_rbac.py b/tests/controller/test_rbac.py index a9cccad75..0378085cb 100644 --- a/tests/controller/test_rbac.py +++ b/tests/controller/test_rbac.py @@ -146,6 +146,27 @@ class TestPrivileges: authorized = await RbacRepository(db_session).check_user_has_privilege(test_user.user_id, path, privilege) assert authorized is True + async def test_delete_all_ace_starting_with_path_is_committed(self, db_session: AsyncSession): + """ + Production requests get a fresh session that is only closed at + teardown, rolling back uncommitted work: the bulk ACE deletion must + be committed to survive the end of the request. + """ + + rbac_repo = RbacRepository(db_session) + group_id = (await UsersRepository(db_session).get_user_group_by_name("Users")).user_group_id + role_id = (await rbac_repo.get_role_by_name("User")).role_id + path = f"/projects/{uuid.uuid4()}" + await rbac_repo.create_ace( + ACECreate(path=path, ace_type="group", propagate=False, group_id=str(group_id), role_id=str(role_id)) + ) + + await rbac_repo.delete_all_ace_starting_with_path(path) + # simulate the production session teardown: close() rolls back the + # open transaction and an uncommitted deletion would be lost + await db_session.rollback() + assert await rbac_repo.check_ace_exists(path) is False + class TestResourcePools: async def test_resource_pool(self, test_user: User, db_session: AsyncSession):