Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
ldap: Use savepoint=True to avoid breaking ldap sync transaction.
Mateusz Mandera4bd6fd63074e
diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.pyindex bdca6a2ff7b..29e00d4f996 100644--- a/tools/linter_lib/custom_check.py+++ b/tools/linter_lib/custom_check.py@@ -491,6 +491,10 @@ python_rules = RuleList("zerver/tests/test_subs.py","with transaction.atomic(savepoint=True), self.assertRaises(JsonableError):",),+ (+ "zproject/backends.py",+ "@transaction.atomic(savepoint=True) # intentional use of savepoint=True",+ ),},},*whitespace_rules,diff --git a/zproject/backends.py b/zproject/backends.pyindex b2faab40e15..3cef1bec5b6 100644--- a/zproject/backends.py+++ b/zproject/backends.py@@ -1316,7 +1316,16 @@ class ZulipLDAPUser(_LDAPUser):assert isinstance(external_auth_id, str)return external_auth_id- @transaction.atomic(savepoint=False)+ # We intentionally want to create a transaction savepoint here. This only+ # runs when syncing a user with LDAP during login or sync_ldap_user_data job+ # and the performance cost should be negligible.+ # A savepoint is needed because sync_ldap_user_data runs inside a large transaction+ # syncing all users. LDAP sync exceptions can propagate through here, to be caught+ # and logged up the callstack.+ # When that occurs, we actually want to roll back this subtransaction, while allowing+ # sync_ldap_user_data to go on to sync other users, without breaking its outermost+ # transactions - which savepoint=False would do.+ @transaction.atomic(savepoint=True) # intentional use of savepoint=Truedef _get_or_create_user(self, force_populate: bool = False) -> UserProfile:# This function is responsible for the core logic of syncing# a user's data with ldap - run in both populate_user codepath