Browse Source

fix(ownership-rules): Fix auto-assignment cache clear on update (#50069)

Only clear the auto-assignment cache on update/save if they have
auto-assignment types

Fixes SENTRY-119B
Jodi Jang 1 year ago
parent
commit
67951f540e

+ 4 - 3
src/sentry/api/endpoints/project_ownership.py

@@ -135,9 +135,10 @@ class ProjectOwnershipSerializer(serializers.Serializer):
             new_values["suspect_committer_auto_assignment"] = False
         if auto_assignment == "Turn off Auto-Assignment":
             autoassignment_types = ProjectOwnership._get_autoassignment_types(ownership)
-            GroupOwner.invalidate_autoassigned_owner_cache(
-                ownership.project_id, autoassignment_types
-            )
+            if autoassignment_types:
+                GroupOwner.invalidate_autoassigned_owner_cache(
+                    ownership.project_id, autoassignment_types
+                )
             new_values["auto_assignment"] = False
             new_values["suspect_committer_auto_assignment"] = False
 

+ 10 - 0
tests/sentry/api/endpoints/test_project_ownership.py

@@ -121,6 +121,16 @@ class ProjectOwnershipEndpointTestCase(APITestCase):
         assert resp.status_code == 200
         assert resp.data["autoAssignment"] == "Turn off Auto-Assignment"
 
+        # Test that we can reset autoAssignment for updating in non-UI use case
+        resp = self.client.put(self.path, {"autoAssignment": "Turn off Auto-Assignment"})
+        assert resp.status_code == 200
+        assert resp.data["fallthrough"] is False
+        assert resp.data["autoAssignment"] == "Turn off Auto-Assignment"
+        assert resp.data["raw"] == "*.js admin@localhost #tiger-team"
+        assert resp.data["dateCreated"] is not None
+        assert resp.data["lastUpdated"] is not None
+        assert resp.data["codeownersAutoSync"] is False
+
     def test_audit_log_entry(self):
         resp = self.client.put(self.path, {"autoAssignment": "Auto Assign to Issue Owner"})
         assert resp.status_code == 200