Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sentry/identity/services/identity/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_provider(
else {"type": provider_type, "external_id": provider_ext_id}
)

idp = IdentityProvider.objects.filter(**idp_kwargs).first()
idp = IdentityProvider.objects.filter(**idp_kwargs).first() # noqa: S034

return serialize_identity_provider(idp) if idp else None

Expand Down Expand Up @@ -93,7 +93,7 @@ def delete_identities(self, user_id: int, organization_id: int) -> None:
ai.delete()

def update_data(self, *, identity_id: int, data: Any) -> RpcIdentity | None:
identity: Identity | None = Identity.objects.filter(id=identity_id).first()
identity: Identity | None = Identity.objects.filter(id=identity_id).first() # noqa: S034
if identity is None:
return None
identity.update(data=data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _validate_and_set_organization_integration(self) -> None:
status=ObjectStatus.ACTIVE,
)
.select_related("integration")
.first()
.first() # noqa: S034
)
if org_integration is None:
raise IntegrationProxyRequestValidationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _auto_create_repository(
organization_id=organization.id,
provider=repo_provider,
status=ObjectStatus.ACTIVE,
).first()
).first() # noqa: S034
return existing, None

@extend_schema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def delete(
# NOTE(hybrid-cloud): Deletions require the ORM object, not API versions
org_integration: OrganizationIntegration | None = OrganizationIntegration.objects.filter(
integration_id=integration_id, organization_id=organization_context.organization.id
).first()
).first() # noqa: S034
if not org_integration:
raise Http404
# A repeated DELETE must not uninstall again. Uninstall hooks that skip
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/bitbucket/installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def post(self, request: Request, *args: object, **kwargs: object) -> Response:
existing = Integration.objects.filter(
provider=IntegrationProviderSlug.BITBUCKET.value,
external_id=client_key,
).first()
).first() # noqa: S034

if existing:
try:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/cursor_origin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _refresh_access_token(self) -> AccessTokenData | None:
# Re-read and write only the metadata: saving the copy read before the request would
# undo a rename or an uninstall that landed meanwhile. No row lock, since locks on
# control tables have stalled the control database before.
integration = Integration.objects.filter(id=self.integration.id).first()
integration = Integration.objects.filter(id=self.integration.id).first() # noqa: S034
if not integration:
return None
integration.metadata.update({"access_token": token, "expires_at": expires_at})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, request: DiscordRequest) -> None:
def group(self) -> Group | None:
try:
group_id = int(self.group_id)
return Group.objects.filter(id=group_id).first()
return Group.objects.filter(id=group_id).first() # noqa: S034
except Exception:
return None

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/gcp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def generate_sentry_sa(org_id: int) -> str:
existing = GcpServiceAccount.objects.filter(organization_id=org_id).first()
existing = GcpServiceAccount.objects.filter(organization_id=org_id).first() # noqa: S034
if existing:
return existing.service_account_email

Expand Down
4 changes: 2 additions & 2 deletions src/sentry/integrations/github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _get_jwt(self) -> str:

@control_silo_function
def _refresh_access_token(self) -> AccessTokenData | None:
integration = Integration.objects.filter(id=self.integration.id).first()
integration = Integration.objects.filter(id=self.integration.id).first() # noqa: S034
if not integration:
return None

Expand Down Expand Up @@ -499,7 +499,7 @@ def authorize_request(self, prepared_request: PreparedRequest) -> PreparedReques
organizationintegration__id=self.org_integration_id,
provider=EXTERNAL_PROVIDERS[ExternalProviders.GITHUB],
status=ObjectStatus.ACTIVE,
).first()
).first() # noqa: S034

if not integration:
logger.info("no_integration", extra={"path_url": prepared_request.path_url})
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/github/issue_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def sync_assignee_outbound(
user_id=user.id,
integration_id=external_issue.integration_id,
organization=external_issue.organization,
).first()
).first() # noqa: S034
if not external_actor:
logger.info(
"assignee-outbound.external-actor-not-found",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/gitlab/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def build_integration(self, state: Mapping[str, Any]) -> IntegrationData:
# Hooks on GitLab outlive the org integration that created them, so the
# secret has to survive a reinstall. No status filter: a disabled row still
# owns hooks carrying its secret.
existing = Integration.objects.filter(provider=self.key, external_id=external_id).first()
existing = Integration.objects.filter(provider=self.key, external_id=external_id).first() # noqa: S034
webhook_secret = existing.metadata.get("webhook_secret") if existing else None
if not webhook_secret:
webhook_secret = secrets.token_hex(20)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/gitlab/issue_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def sync_assignee_outbound(
user_id=user.id,
integration_id=external_issue.integration_id,
organization=external_issue.organization,
).first()
).first() # noqa: S034
if not external_actor:
logger.info("assignee-outbound.external-actor-not-found", extra=log_context)
return
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/integrations/jira/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def sync_metadata(integration_id: int) -> None:
from sentry.integrations.jira_server.integration import JiraServerIntegration

integration = Integration.objects.get(id=integration_id)
org_install = integration.organizationintegration_set.first()
org_install = integration.organizationintegration_set.first() # noqa: S034
if not org_install:
return
installation = integration.get_installation(org_install.organization_id)
Expand Down Expand Up @@ -60,7 +60,7 @@ def sync_forge_installation(key_id: str, encrypted_payload: str) -> None:
# site has a Connect integration keyed by its clientKey. A failed lookup is retried,
# never taken to mean there's no Connect integration.
# 3. Otherwise, create a Forge-only integration keyed by the cloud ID.
integration = Integration.objects.filter(provider="jira", external_id=cloud_id).first()
integration = Integration.objects.filter(provider="jira", external_id=cloud_id).first() # noqa: S034
if integration is None and payload["app_id"] not in options.get("jira.forge.native-app-ids"):
client_key = client.get_connect_client_key()
integration = Integration.objects.get(provider="jira", external_id=client_key)
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/integrations/linear/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def get_access_token(
# usable replacement, hand that out instead of failing.
integration = Integration.objects.filter(
id=self.integration.id, status=ObjectStatus.ACTIVE
).first()
).first() # noqa: S034
if integration is None:
return None
token = _reusable_stored_token(integration, minimum_validity, force_refresh)
Expand All @@ -285,7 +285,7 @@ def get_access_token(
with acquired:
integration = Integration.objects.filter(
id=self.integration.id, status=ObjectStatus.ACTIVE
).first()
).first() # noqa: S034
if integration is None:
return None
metadata = integration.metadata
Expand All @@ -303,7 +303,7 @@ def get_access_token(
# The date_updated filter catches stamped writes atomically; re-reading the
# stored refresh token also covers writers that persist new credentials
# without bumping date_updated.
current = Integration.objects.filter(id=integration.id).first()
current = Integration.objects.filter(id=integration.id).first() # noqa: S034
if current is not None and current.metadata.get("refresh_token") == refresh_token:
Integration.objects.filter(
id=integration.id,
Expand Down Expand Up @@ -336,7 +336,7 @@ def revoke_access(self, organization_id: int) -> None:
.exists()
):
return
integration = Integration.objects.filter(id=self.integration.id).first()
integration = Integration.objects.filter(id=self.integration.id).first() # noqa: S034
if integration is None:
return
refresh_token = integration.metadata.get("refresh_token")
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/msteams/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def _handle_action_submitted(self, request: Request) -> Response:
team_id = integration.external_id
client = MsTeamsClient(integration)

group = Group.objects.select_related("project__organization").filter(id=group_id).first()
group = Group.objects.select_related("project__organization").filter(id=group_id).first() # noqa: S034
if group:
integration = integration_service.get_integration(
integration_id=integration.id,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _install_integration_transaction(self, data: IntegrationData) -> Organizatio
provider=self.provider.integration_key,
external_id=data["external_id"],
status=ObjectStatus.ACTIVE,
).first()
).first() # noqa: S034
if integration is None:
raise IntegrationError(
"This installation no longer exists. Reinstall the app and try again."
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/services/integration/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def get_access_token(
status=ObjectStatus.ACTIVE,
organizationintegration__organization_id=organization_id,
organizationintegration__status=ObjectStatus.ACTIVE,
).first()
).first() # noqa: S034
if integration is None:
return None

Expand Down
10 changes: 5 additions & 5 deletions src/sentry/integrations/services/repository/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def serialize_repository(
id: int,
as_user: RpcUser | None = None,
) -> Any | None:
repository = Repository.objects.filter(organization_id=organization_id, id=id).first()
repository = Repository.objects.filter(organization_id=organization_id, id=id).first() # noqa: S034
if repository is None:
return None
return serialize(repository, user=as_user)
Expand Down Expand Up @@ -89,7 +89,7 @@ def get_repositories(
return [serialize_repository(repo) for repo in query]

def get_repository(self, *, organization_id: int, id: int) -> RpcRepository | None:
repository = Repository.objects.filter(organization_id=organization_id, id=id).first()
repository = Repository.objects.filter(organization_id=organization_id, id=id).first() # noqa: S034
if repository is None:
return None
return serialize_repository(repository)
Expand All @@ -111,7 +111,7 @@ def update_repository(self, *, organization_id: int, update: RpcRepository) -> N
repository = (
Repository.objects.filter(organization_id=organization_id, id=update.id)
.select_for_update()
.first()
.first() # noqa: S034
)
if repository is None:
return
Expand All @@ -138,7 +138,7 @@ def update_repository_config(
repository = (
Repository.objects.filter(organization_id=organization_id, id=id)
.select_for_update()
.first()
.first() # noqa: S034
)
if repository is None or repository.status != ObjectStatus.ACTIVE:
return False
Expand Down Expand Up @@ -203,7 +203,7 @@ def transfer_repository_to_integration(
repository = (
Repository.objects.filter(organization_id=organization_id, id=update.id)
.select_for_update()
.first()
.first() # noqa: S034
)
if repository is None or repository.status not in (
ObjectStatus.ACTIVE,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/slack/sdk_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, integration_id: int):
else: # control or monolith (local)
integration = Integration.objects.filter(
id=integration_id, status=ObjectStatus.ACTIVE
).first()
).first() # noqa: S034

if integration is None:
raise ValueError(f"Integration with id {integration_id} not found")
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/slack/webhooks/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_notification_origin(
def get_group(slack_request: SlackActionRequest) -> Group | None:
"""Determine the issue group on which an action is being taken."""
group_id = slack_request.callback_data["issue"]
group = Group.objects.select_related("project__organization").filter(id=group_id).first()
group = Group.objects.select_related("project__organization").filter(id=group_id).first() # noqa: S034
if group:
if not integration_service.get_organization_integration(
organization_id=group.project.organization_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def log_unavailable(
log_unavailable(InvestigationUnavailableReason.INTEGRATION_NOT_INSTALLED)
return _respond_ephemeral(INVESTIGATION_UNAVAILABLE_MESSAGE)

organization = Organization.objects.filter(id=organization_id).first()
organization = Organization.objects.filter(id=organization_id).first() # noqa: S034
if organization is None:
log_unavailable(InvestigationUnavailableReason.ORGANIZATION_NOT_FOUND)
return _respond_ephemeral(INVESTIGATION_UNAVAILABLE_MESSAGE)
Expand All @@ -170,7 +170,7 @@ def log_unavailable(
user_id=identity_user.id,
organization_id=organization.id,
invite_status=InviteStatus.APPROVED.value,
).first()
).first() # noqa: S034
if member is None:
log_unavailable(InvestigationUnavailableReason.NOT_MEMBER)
return _respond_ephemeral(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def handle_seer_agent_write_approval(
if slack_user_id is None:
return _respond_ephemeral(AGENT_WRITE_APPROVAL_UNAVAILABLE_MESSAGE)

organization = Organization.objects.filter(id=organization_id).first()
organization = Organization.objects.filter(id=organization_id).first() # noqa: S034
if not organization or not SeerAgentOperator.has_access(
organization=organization,
entrypoint_key=SeerEntrypointKey.SLACK,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/slack/webhooks/options_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def post(self, request: Request) -> Response:
group = (
Group.objects.select_related("project__organization")
.filter(id=slack_request.group_id)
.first()
.first() # noqa: S034
)

if group and not integration_service.get_organization_integrations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def create_or_update_comment(

pr_comment = PullRequestComment.objects.filter(
pull_request__id=pr.id, comment_type=comment_type
).first()
).first() # noqa: S034

interaction_type = (
SCMIntegrationInteractionType.CREATE_COMMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def bump_org_integration_last_sync(
`repos_changed` is True, also stamp `config["last_repos_change"]` to record
the last time the repo set actually changed.
"""
oi = OrganizationIntegration.objects.filter(id=organization_integration_id).first()
oi = OrganizationIntegration.objects.filter(id=organization_integration_id).first() # noqa: S034
if oi is None:
return
now = timezone.now().isoformat()
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/tasks/sync_status_inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def sync_status_inbound(
# late writes an old status over a newer one.
external_issue = ExternalIssue.objects.filter(
organization_id=organization_id, integration_id=integration_id, key=issue_key
).first()
).first() # noqa: S034
event_time = parse_provider_event_time(data)
if external_issue is not None and is_stale_status_event(
external_issue.provider_status_updated_at, event_time
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/utils/atlassian_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ def parse_integration_from_request(request: HttpRequest, provider: str) -> Integ
query_params=request.GET,
method=request.method if request.method else "POST",
)
return Integration.objects.filter(id=rpc_integration.id).first()
return Integration.objects.filter(id=rpc_integration.id).first() # noqa: S034
4 changes: 2 additions & 2 deletions src/sentry/integrations/utils/identities.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def get_identity_or_404(
_logger.info("provider is not part of supported external providers", extra=logger_metadata)
raise Http404

integration = Integration.objects.filter(id=integration_id).first()
integration = Integration.objects.filter(id=integration_id).first() # noqa: S034
if integration is None:
_logger.info("failed to find an integration", extra=logger_metadata)
raise Http404

idp = IdentityProvider.objects.filter(
external_id=integration.external_id, type=integration.provider
).first()
).first() # noqa: S034
logger_metadata["external_id"] = integration.external_id
if idp is None:
_logger.info("failed to find an identity provider", extra=logger_metadata)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/notifications/notification_action/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def create_notification_origin(
alert_rule_workflow = AlertRuleWorkflow.objects.filter(
workflow_id=workflow_id,
rule_id__isnull=False,
).first()
).first() # noqa: S034
if alert_rule_workflow:
assert alert_rule_workflow.rule_id is not None
if Rule.objects.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _get_user_option(assignee_id: int | None) -> RpcUser | None:
def _get_team_option(assignee_id: int | None, organization: Organization) -> Team | None:
if assignee_id is None:
return None
return Team.objects.filter(id=assignee_id, organization=organization).first()
return Team.objects.filter(id=assignee_id, organization=organization).first() # noqa: S034


def is_team_assignee(activity: Activity) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_issue_owner_ids(self) -> tuple[set[int], set[int]]:
user_ids: set[int] = set()
team_ids: set[int] = set()

assignee = GroupAssignee.objects.filter(group=self.group).first()
assignee = GroupAssignee.objects.filter(group=self.group).first() # noqa: S034
if assignee is not None:
if assignee.user_id is not None:
user_ids.add(assignee.user_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def notification_context(self) -> NotificationContext:
return context

workflow_name = (
Workflow.objects.filter(id=workflow_id).values_list("name", flat=True).first()
Workflow.objects.filter(id=workflow_id).values_list("name", flat=True).first() # noqa: S034
)
if workflow_name is None:
return context
Expand Down
Loading
Loading