Просмотр исходного кода

fix(dynamic-sampling): Fix Organization.DoesNotExist error (#49532)

Riccardo Busetti 1 год назад
Родитель
Сommit
f0d75d3345
1 измененных файлов с 10 добавлено и 3 удалено
  1. 10 3
      src/sentry/dynamic_sampling/tasks.py

+ 10 - 3
src/sentry/dynamic_sampling/tasks.py

@@ -278,11 +278,18 @@ def adjust_sample_rates(
     and store it in DS redis cluster, then we invalidate project config
     so relay can reread it, and we'll inject it from redis cache.
     """
-    # We need the organization object for the feature flag.
-    organization = Organization.objects.get_from_cache(id=org_id)
+    try:
+        # We need the organization object for the feature flag.
+        organization = Organization.objects.get_from_cache(id=org_id)
+    except Organization.DoesNotExist:
+        # In case an org is not found, it might be that it has been deleted in the time between
+        # the query triggering this job and the actual execution of the job.
+        organization = None
 
     # We get the sample rate either directly from quotas or from the new sliding window org mechanism.
-    if features.has("organizations:ds-sliding-window-org", organization, actor=None):
+    if organization is not None and features.has(
+        "organizations:ds-sliding-window-org", organization, actor=None
+    ):
         sample_rate = get_adjusted_base_rate_from_cache_or_compute(org_id)
     else:
         sample_rate = quotas.get_blended_sample_rate(organization_id=org_id)