From 07a35a684b0387b97d0422312cf9588d45eb26ff Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 5 Sep 2017 16:51:04 +0300 Subject: [PATCH 1/2] added locks on tables without primary keys --- lingvodoc/views/v2/dictionary.py | 2 ++ lingvodoc/views/v2/perspective/views.py | 2 ++ lingvodoc/views/v2/userrequests.py | 1 + 3 files changed, 5 insertions(+) diff --git a/lingvodoc/views/v2/dictionary.py b/lingvodoc/views/v2/dictionary.py index 51dd9c175..fc6b34c45 100644 --- a/lingvodoc/views/v2/dictionary.py +++ b/lingvodoc/views/v2/dictionary.py @@ -592,6 +592,8 @@ def view_dictionary_roles(request): # tested & in docs @view_config(route_name='dictionary_roles', renderer='json', request_method='POST', permission='create') def edit_dictionary_roles(request): # tested & in docs + DBSession.execute("LOCK TABLE user_to_group_association IN EXCLUSIVE MODE;") + DBSession.execute("LOCK TABLE organization_to_group_association IN EXCLUSIVE MODE;") response = dict() client_id = request.matchdict.get('client_id') object_id = request.matchdict.get('object_id') diff --git a/lingvodoc/views/v2/perspective/views.py b/lingvodoc/views/v2/perspective/views.py index 9f858982f..d97dd248b 100644 --- a/lingvodoc/views/v2/perspective/views.py +++ b/lingvodoc/views/v2/perspective/views.py @@ -1009,6 +1009,8 @@ def view_perspective_roles(request): # TODO: test @view_config(route_name='perspective_roles', renderer='json', request_method='POST', permission='create') def edit_perspective_roles(request): + DBSession.execute("LOCK TABLE user_to_group_association IN EXCLUSIVE MODE;") + DBSession.execute("LOCK TABLE organization_to_group_association IN EXCLUSIVE MODE;") response = dict() client_id = request.matchdict.get('perspective_client_id') object_id = request.matchdict.get('perspective_object_id') diff --git a/lingvodoc/views/v2/userrequests.py b/lingvodoc/views/v2/userrequests.py index 351420e45..ce8776104 100644 --- a/lingvodoc/views/v2/userrequests.py +++ b/lingvodoc/views/v2/userrequests.py @@ -235,6 +235,7 @@ def accept_userrequest(request): # group.users.append(admin) elif userrequest.type == 'participate_org': + DBSession.execute("LOCK TABLE user_to_organization_association IN EXCLUSIVE MODE;") org_id = userrequest.subject['org_id'] user_id = userrequest.subject['user_id'] organization = DBSession.query(Organization).filter_by(id=org_id).first() From e09517368117987d62e45e27c5318eb08fae1869 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 5 Sep 2017 16:52:54 +0300 Subject: [PATCH 2/2] additional lock --- lingvodoc/views/v2/organization.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lingvodoc/views/v2/organization.py b/lingvodoc/views/v2/organization.py index 34d25cd63..2ea9a3a69 100644 --- a/lingvodoc/views/v2/organization.py +++ b/lingvodoc/views/v2/organization.py @@ -137,6 +137,7 @@ def view_organization(request): # TODO: test @view_config(route_name='organization', renderer='json', request_method='PUT') def edit_organization(request): # TODO: test try: + DBSession.execute("LOCK TABLE user_to_organization_association IN EXCLUSIVE MODE;") response = dict() organization_id = request.matchdict.get('organization_id') organization = DBSession.query(Organization).filter_by(id=organization_id).first()