Skip to content

Commit ec766b1

Browse files
authored
fix(integrations): User is None (#28955)
1 parent 5cfbd4b commit ec766b1

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

src/sentry/db/models/manager/base_query_set.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def using_replica(self) -> "BaseQuerySet":
1717
Use read replica for this query. Database router is expected to use the
1818
`replica=True` hint to make routing decision.
1919
"""
20-
return self.using(router.db_for_read(self.model, replica=True))
20+
# Explicitly typing to satisfy mypy.
21+
query_set: "BaseQuerySet" = self.using(router.db_for_read(self.model, replica=True))
22+
return query_set
2123

2224
def defer(self, *args: Any, **kwargs: Any) -> "BaseQuerySet":
2325
raise NotImplementedError("Use ``values_list`` instead [performance].")

src/sentry/integrations/example/integration.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, Optional
2+
13
from django.http import HttpResponse
24

35
from sentry.integrations import (
@@ -9,7 +11,7 @@
911
)
1012
from sentry.integrations.issues import IssueSyncMixin
1113
from sentry.mediators.plugins import Migrator
12-
from sentry.models import User
14+
from sentry.models import ExternalIssue, User
1315
from sentry.pipeline import PipelineView
1416
from sentry.shared_integrations.exceptions import IntegrationError
1517

@@ -127,7 +129,13 @@ def get_repositories(self):
127129
def get_unmigratable_repositories(self):
128130
return []
129131

130-
def sync_assignee_outbound(self, external_issue, user, assign=True, **kwargs):
132+
def sync_assignee_outbound(
133+
self,
134+
external_issue: "ExternalIssue",
135+
user: Optional["User"],
136+
assign: bool = True,
137+
**kwargs: Any,
138+
) -> None:
131139
pass
132140

133141
def sync_status_outbound(self, external_issue, is_resolved, project_id):

src/sentry/integrations/issues.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import logging
22
from collections import defaultdict
3+
from typing import Any, Optional
34

45
from sentry import features
5-
from sentry.models import ExternalIssue, Group, GroupLink, GroupStatus, Organization
6+
from sentry.models import ExternalIssue, Group, GroupLink, GroupStatus, Organization, User
67
from sentry.models.useroption import UserOption
78
from sentry.shared_integrations.exceptions import ApiError, IntegrationError
89
from sentry.types.activity import ActivityType
@@ -306,7 +307,13 @@ def should_sync(self, attribute: str) -> bool:
306307
value: bool = self.org_integration.config.get(key, False)
307308
return value
308309

309-
def sync_assignee_outbound(self, external_issue, user, assign=True, **kwargs):
310+
def sync_assignee_outbound(
311+
self,
312+
external_issue: "ExternalIssue",
313+
user: Optional["User"],
314+
assign: bool = True,
315+
**kwargs: Any,
316+
) -> None:
310317
"""
311318
Propagate a sentry issue's assignee to a linked issue's assignee.
312319
If assign=True, we're assigning the issue. Otherwise, deassign.

src/sentry/integrations/jira/integration.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import re
33
from operator import attrgetter
4+
from typing import Any, Optional
45

56
from django.conf import settings
67
from django.urls import reverse
@@ -15,7 +16,13 @@
1516
IntegrationProvider,
1617
)
1718
from sentry.integrations.issues import IssueSyncMixin
18-
from sentry.models import IntegrationExternalProject, Organization, OrganizationIntegration, User
19+
from sentry.models import (
20+
ExternalIssue,
21+
IntegrationExternalProject,
22+
Organization,
23+
OrganizationIntegration,
24+
User,
25+
)
1926
from sentry.shared_integrations.exceptions import (
2027
ApiError,
2128
ApiUnauthorized,
@@ -827,14 +834,20 @@ def create_issue(self, data, **kwargs):
827834
# Immediately fetch and return the created issue.
828835
return self.get_issue(issue_key)
829836

830-
def sync_assignee_outbound(self, external_issue, user, assign=True, **kwargs):
837+
def sync_assignee_outbound(
838+
self,
839+
external_issue: "ExternalIssue",
840+
user: Optional["User"],
841+
assign: bool = True,
842+
**kwargs: Any,
843+
) -> None:
831844
"""
832845
Propagate a sentry issue's assignee to a jira issue's assignee
833846
"""
834847
client = self.get_client()
835848

836849
jira_user = None
837-
if assign:
850+
if user and assign:
838851
for ue in user.emails.filter(is_verified=True):
839852
try:
840853
possible_users = client.search_users_for_issue(external_issue.key, ue.email)
@@ -873,7 +886,7 @@ def sync_assignee_outbound(self, external_issue, user, assign=True, **kwargs):
873886
extra={
874887
"organization_id": external_issue.organization_id,
875888
"integration_id": external_issue.integration_id,
876-
"user_id": user.id,
889+
"user_id": user.id if user else None,
877890
"issue_key": external_issue.key,
878891
},
879892
)

src/sentry/integrations/vsts/issues.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,16 @@ def get_issue(self, issue_id: str, **kwargs: Any) -> Mapping[str, Any]:
208208
}
209209

210210
def sync_assignee_outbound(
211-
self, external_issue: "ExternalIssue", user: User, assign: bool = True, **kwargs: Any
211+
self,
212+
external_issue: "ExternalIssue",
213+
user: Optional["User"],
214+
assign: bool = True,
215+
**kwargs: Any,
212216
) -> None:
213217
client = self.get_client()
214218
assignee = None
215219

216-
if assign is True:
220+
if user and assign is True:
217221
sentry_emails = [email.email.lower() for email in user.get_verified_emails()]
218222
continuation_token = None
219223
while True:
@@ -247,7 +251,7 @@ def sync_assignee_outbound(
247251
"vsts.failed-to-assign",
248252
extra={
249253
"integration_id": external_issue.integration_id,
250-
"user_id": user.id,
254+
"user_id": user.id if user else None,
251255
"issue_key": external_issue.key,
252256
},
253257
)

0 commit comments

Comments
 (0)