|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from collections.abc import Iterable
|
4 | 5 | from typing import Any
|
5 | 6 |
|
6 | 7 | from sentry import features
|
7 |
| -from sentry.models.organization import Organization |
| 8 | +from sentry.models.organization import Organization, OrganizationStatus |
8 | 9 | from sentry.silo.base import SiloMode
|
9 | 10 | from sentry.tasks.base import instrumented_task, load_model_from_db, retry
|
10 | 11 | from sentry.taskworker.config import TaskworkerConfig
|
11 | 12 | from sentry.taskworker.namespaces import issues_tasks
|
12 | 13 | from sentry.taskworker.retry import Retry
|
13 | 14 |
|
| 15 | +logger = logging.getLogger(__name__) |
| 16 | + |
14 | 17 |
|
15 | 18 | @instrumented_task(
|
16 | 19 | name="sentry.tasks.update_code_owners_schema",
|
@@ -38,7 +41,22 @@ def update_code_owners_schema(
|
38 | 41 | )
|
39 | 42 | from sentry.models.projectcodeowners import ProjectCodeOwners
|
40 | 43 |
|
41 |
| - org = load_model_from_db(Organization, organization) |
| 44 | + # This task is enqueued when projects and teams are deleted. If the |
| 45 | + # organization itself has also been deleted we're all done here. |
| 46 | + try: |
| 47 | + org = load_model_from_db(Organization, organization) |
| 48 | + except Organization.DoesNotExist: |
| 49 | + logger.warning( |
| 50 | + "Skipping update_code_owners_schema: organization does not exist", |
| 51 | + extra={"organization_id": organization, "integration_id": integration}, |
| 52 | + ) |
| 53 | + return |
| 54 | + if org.status == OrganizationStatus.DELETION_IN_PROGRESS: |
| 55 | + logger.warning( |
| 56 | + "Skipping update_code_owners_schema: organization deletion in progress", |
| 57 | + extra={"organization_id": organization, "integration_id": integration}, |
| 58 | + ) |
| 59 | + return |
42 | 60 |
|
43 | 61 | if not features.has("organizations:integrations-codeowners", org):
|
44 | 62 | return
|
|
0 commit comments