From 8e76decbe0b169c93afba988b14893838ca3bc24 Mon Sep 17 00:00:00 2001 From: Leander Rodrigues Date: Thu, 12 Nov 2026 14:49:04 -0500 Subject: [PATCH] ref(seer): Mark unordered .first() calls with noqa: S034 Grandfather existing call sites ahead of the S034 lint rule. Refs ISWF-3679 --- src/sentry/agent_handoff/applications.py | 2 +- src/sentry/agent_handoff/claims.py | 2 +- src/sentry/investigations/notebook_producer.py | 4 ++-- src/sentry/investigations/services/issue_links.py | 4 ++-- src/sentry/investigations/services/orchestration.py | 8 ++++---- .../investigations/services/orchestration_events.py | 4 ++-- src/sentry/notebooks/agent.py | 4 ++-- src/sentry/notebooks/endpoints/validators/comment.py | 2 +- src/sentry/notebooks/presence.py | 2 +- src/sentry/notebooks/services/action_requests.py | 4 ++-- src/sentry/notebooks/services/executions.py | 2 +- src/sentry/notebooks/services/producer_writes.py | 4 ++-- src/sentry/notebooks/tasks.py | 2 +- src/sentry/seer/agent/client.py | 2 +- src/sentry/seer/agent/tools.py | 6 +++--- src/sentry/seer/agentic_triage/delivery.py | 2 +- src/sentry/seer/anomaly_detection/delete_rule.py | 2 +- .../seer/anomaly_detection/store_data_workflow_engine.py | 2 +- src/sentry/seer/autofix/autofix_agent.py | 6 +++--- src/sentry/seer/autofix/feature/delivery.py | 2 +- src/sentry/seer/autofix/on_completion_hook.py | 6 +++--- src/sentry/seer/autofix/pr_iteration/cap_exhausted.py | 2 +- src/sentry/seer/autofix/pr_iteration/check_suites.py | 2 +- src/sentry/seer/autofix/pr_iteration/current_iteration.py | 2 +- src/sentry/seer/autofix/pr_iteration/details_store.py | 2 +- src/sentry/seer/autofix/pr_iteration/emit.py | 4 ++-- .../seer/autofix/pr_iteration/missing_permissions.py | 4 ++-- src/sentry/seer/autofix/pr_iteration/pause.py | 2 +- .../seer/autofix/pr_iteration/reviewer_candidates.py | 2 +- src/sentry/seer/autofix/webhooks.py | 4 ++-- src/sentry/seer/code_review/preflight.py | 2 +- src/sentry/seer/endpoints/organization_seer_agent_chat.py | 2 +- .../seer/endpoints/organization_seer_chat_suggestions.py | 4 ++-- src/sentry/seer/endpoints/project_seer_repos.py | 2 +- src/sentry/seer/endpoints/utils.py | 4 ++-- src/sentry/seer/entrypoints/slack/investigation_status.py | 2 +- src/sentry/seer/fetch_issues/utils.py | 2 +- src/sentry/seer/similarity/similar_issues.py | 4 ++-- src/sentry/seer/similarity/types.py | 2 +- src/sentry/seer/smart_assignment/completion.py | 2 +- src/sentry/seer/smart_assignment/delivery.py | 4 ++-- src/sentry/seer/smart_assignment/scoring.py | 4 ++-- src/sentry/seer/workflows/action.py | 2 +- src/sentry/seer/workflows/breached_metrics.py | 4 ++-- src/sentry/seer/workflows/runs.py | 4 ++-- 45 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/sentry/agent_handoff/applications.py b/src/sentry/agent_handoff/applications.py index 62ca9056bc55..90933b187d29 100644 --- a/src/sentry/agent_handoff/applications.py +++ b/src/sentry/agent_handoff/applications.py @@ -11,7 +11,7 @@ def get_handoff_application(scope_list: Sequence[str]) -> ApiApplication | None: application = ApiApplication.objects.filter( client_id=client_id, status=ApiApplicationStatus.active - ).first() + ).first() # noqa: S034 if ( application is None or not application.is_public diff --git a/src/sentry/agent_handoff/claims.py b/src/sentry/agent_handoff/claims.py index 24f000879455..eee5833e8e20 100644 --- a/src/sentry/agent_handoff/claims.py +++ b/src/sentry/agent_handoff/claims.py @@ -24,7 +24,7 @@ def claim_handoff(code: str, *, ip_address: str | None) -> str | None: if handoff is None: return None - user = User.objects.filter(id=handoff.user_id, is_active=True, is_suspended=False).first() + user = User.objects.filter(id=handoff.user_id, is_active=True, is_suspended=False).first() # noqa: S034 application = get_handoff_application(handoff.scope_list) if user is None or application is None or application.id != handoff.application_id: return None diff --git a/src/sentry/investigations/notebook_producer.py b/src/sentry/investigations/notebook_producer.py index 50e1d7ff765b..2b8090e62d07 100644 --- a/src/sentry/investigations/notebook_producer.py +++ b/src/sentry/investigations/notebook_producer.py @@ -68,7 +68,7 @@ def _queue_follow_up( ), ) .values_list("request_id", flat=True) - .first() + .first() # noqa: S034 ) if queued is not None: return queued @@ -157,7 +157,7 @@ def _failed_follow_up( orchestration_run__investigation_id=action_request.notebook_id, request_id=action_request.followup_request_id, status=InvestigationOrchestrationCommandStatus.FAILED, - ).first() + ).first() # noqa: S034 class OrchestrationProducerRun(NotebookProducerRun): diff --git a/src/sentry/investigations/services/issue_links.py b/src/sentry/investigations/services/issue_links.py index ca5a03c53253..0addf9da4ad7 100644 --- a/src/sentry/investigations/services/issue_links.py +++ b/src/sentry/investigations/services/issue_links.py @@ -48,7 +48,7 @@ def _linked_group( return ( Group.objects.filter(id=item["groupId"], project_id__in=project_ids) .select_related("project") - .first() + .first() # noqa: S034 ) try: return Group.objects.by_qualified_short_id( @@ -65,7 +65,7 @@ def link_investigation_issues( notebook = ( Notebook.objects.select_related("organization") .filter(id=investigation_id, status=NotebookStatus.ACTIVE) - .first() + .first() # noqa: S034 ) if notebook is None or not issue_links_enabled(notebook.organization): return diff --git a/src/sentry/investigations/services/orchestration.py b/src/sentry/investigations/services/orchestration.py index 4a42baeaadb8..4801b0d3e759 100644 --- a/src/sentry/investigations/services/orchestration.py +++ b/src/sentry/investigations/services/orchestration.py @@ -415,7 +415,7 @@ def archive_investigation_with_orchestration( run = ( InvestigationOrchestrationRun.objects.select_for_update() .filter(investigation=locked_investigation) - .first() + .first() # noqa: S034 ) if run is not None and actor_id is None: raise PermissionDenied @@ -493,7 +493,7 @@ def update_investigation_with_orchestration( run = ( InvestigationOrchestrationRun.objects.select_for_update() .filter(investigation=locked_investigation) - .first() + .first() # noqa: S034 ) if ( run is not None @@ -684,7 +684,7 @@ def create_agentic_breached_metric_investigation( organization=organization, source_key=source_key, status=NotebookStatus.ACTIVE, - ).first() + ).first() # noqa: S034 if active is not None: return active, False raise @@ -830,7 +830,7 @@ def accept_orchestration_command( internal = command_type in INTERNAL_COMMAND_TYPES existing = InvestigationOrchestrationCommand.objects.filter( orchestration_run=run, request_id=request_id - ).first() + ).first() # noqa: S034 if existing is not None: if ( (not internal and existing.expected_workflow_version != expected_workflow_version) diff --git a/src/sentry/investigations/services/orchestration_events.py b/src/sentry/investigations/services/orchestration_events.py index 109e122cb986..99a015ac3b3f 100644 --- a/src/sentry/investigations/services/orchestration_events.py +++ b/src/sentry/investigations/services/orchestration_events.py @@ -1091,7 +1091,7 @@ def _apply_available_events( next_event = InvestigationOrchestrationEvent.objects.filter( orchestration_run=run, sequence=run.last_event_sequence + 1, - ).first() + ).first() # noqa: S034 if next_event is None: break if next_event.application_status != InvestigationOrchestrationEventStatus.PENDING: @@ -1230,7 +1230,7 @@ def deliver_orchestration_event( existing = InvestigationOrchestrationEvent.objects.filter( orchestration_run=run, event_id=event["event_id"] - ).first() + ).first() # noqa: S034 if existing is not None: if ( existing.sequence != event["sequence"] diff --git a/src/sentry/notebooks/agent.py b/src/sentry/notebooks/agent.py index ba52b31dbff7..fe2a08079034 100644 --- a/src/sentry/notebooks/agent.py +++ b/src/sentry/notebooks/agent.py @@ -1219,12 +1219,12 @@ def execute(cls, organization: Organization, run_id: int) -> None: execution = NotebookBlockExecution.objects.filter( seer_run__seer_run_state_id=run_id, block__notebook__organization=organization, - ).first() + ).first() # noqa: S034 if execution is not None: synchronize_execution(execution, state) return notebook = Notebook.objects.filter( organization=organization, title_seer_run__seer_run_state_id=run_id - ).first() + ).first() # noqa: S034 if notebook is not None: synchronize_title(notebook, state) diff --git a/src/sentry/notebooks/endpoints/validators/comment.py b/src/sentry/notebooks/endpoints/validators/comment.py index dc12f1bf2049..61fe7878aeda 100644 --- a/src/sentry/notebooks/endpoints/validators/comment.py +++ b/src/sentry/notebooks/endpoints/validators/comment.py @@ -42,7 +42,7 @@ class CommentCreateValidator(CommentValidator): def validate_block_id(self, value: int) -> NotebookBlock: block = NotebookBlock.objects.filter( id=value, notebook=self.context["notebook"], deleted_at__isnull=True - ).first() + ).first() # noqa: S034 if block is None: raise serializers.ValidationError("Block not found.") return block diff --git a/src/sentry/notebooks/presence.py b/src/sentry/notebooks/presence.py index 0a86d827e523..a41241b93fe5 100644 --- a/src/sentry/notebooks/presence.py +++ b/src/sentry/notebooks/presence.py @@ -98,7 +98,7 @@ def record_visit(notebook: Notebook, user_id: int, limit: int = DEFAULT_VIEWER_L own_last_seen = ( NotebookSeen.objects.filter(notebook=notebook, user_id=user_id) .values_list("last_seen", flat=True) - .first() + .first() # noqa: S034 ) if not heartbeat.was_present or own_last_seen is None or now - own_last_seen >= SEEN_REFRESH: NotebookSeen.objects.update_or_create( diff --git a/src/sentry/notebooks/services/action_requests.py b/src/sentry/notebooks/services/action_requests.py index a26f2d388030..81cd6dc51a7a 100644 --- a/src/sentry/notebooks/services/action_requests.py +++ b/src/sentry/notebooks/services/action_requests.py @@ -152,7 +152,7 @@ def _upsert(notebook: Notebook, item: ActionRequestItem) -> tuple[NotebookAction "rationale": item["rationale"], "impact": item["impact"], } - row = NotebookActionRequest.objects.filter(notebook=notebook, key=item["key"]).first() + row = NotebookActionRequest.objects.filter(notebook=notebook, key=item["key"]).first() # noqa: S034 changed = True if row is None: row = NotebookActionRequest.objects.create( @@ -378,7 +378,7 @@ def complete_action_requests( for notebook_id in notebook_ids: with transaction.atomic(using=router.db_for_write(NotebookActionRequest)): notebook = ( - Notebook.objects.select_for_update(of=("self",)).filter(id=notebook_id).first() + Notebook.objects.select_for_update(of=("self",)).filter(id=notebook_id).first() # noqa: S034 ) if notebook is None: continue diff --git a/src/sentry/notebooks/services/executions.py b/src/sentry/notebooks/services/executions.py index 76ee1dcd95fc..9c8f711f4d29 100644 --- a/src/sentry/notebooks/services/executions.py +++ b/src/sentry/notebooks/services/executions.py @@ -308,7 +308,7 @@ def create_block_execution( ) -> tuple[NotebookBlockExecution, bool]: """Create a new immutable execution, or return the same explicit request retry.""" if request_id is not None: - requested_execution = NotebookBlockExecution.objects.filter(request_id=request_id).first() + requested_execution = NotebookBlockExecution.objects.filter(request_id=request_id).first() # noqa: S034 if requested_execution is not None: if requested_execution.block_id != block.id: raise NotebookValidationError( diff --git a/src/sentry/notebooks/services/producer_writes.py b/src/sentry/notebooks/services/producer_writes.py index 44074b0c0d0f..b1d95666d59d 100644 --- a/src/sentry/notebooks/services/producer_writes.py +++ b/src/sentry/notebooks/services/producer_writes.py @@ -204,7 +204,7 @@ def upsert_block( if block.pk: block.version += 1 block.save() - execution = NotebookBlockExecution.objects.filter(request_id=request_id).first() + execution = NotebookBlockExecution.objects.filter(request_id=request_id).first() # noqa: S034 if execution is not None and execution.block_id != block.id: raise serializers.ValidationError( {"requestId": "This execution request ID is already in use."} @@ -444,7 +444,7 @@ def remove_blocks( def _live_block(notebook: Notebook, key: str) -> NotebookBlock | None: return NotebookBlock.objects.filter( notebook=notebook, producer_key=key, deleted_at__isnull=True - ).first() + ).first() # noqa: S034 def _check_revision(block: NotebookBlock, revision: int) -> None: diff --git a/src/sentry/notebooks/tasks.py b/src/sentry/notebooks/tasks.py index bb13c31ed79b..225a64cb3e39 100644 --- a/src/sentry/notebooks/tasks.py +++ b/src/sentry/notebooks/tasks.py @@ -27,7 +27,7 @@ def dispatch_notebook_execution(execution_id: int) -> None: execution = ( NotebookBlockExecution.objects.select_related("block__notebook__organization") .filter(id=execution_id) - .first() + .first() # noqa: S034 ) if execution is None: return diff --git a/src/sentry/seer/agent/client.py b/src/sentry/seer/agent/client.py index aa1f71bfcbe7..a669f5e3813b 100644 --- a/src/sentry/seer/agent/client.py +++ b/src/sentry/seer/agent/client.py @@ -793,7 +793,7 @@ def continue_run( # the remote run (fail closed). run = SeerRun.objects.filter( organization_id=self.organization.id, seer_run_state_id=run_id - ).first() + ).first() # noqa: S034 if run is None: raise SeerPermissionError(UNKNOWN_RUN_ID_FOR_GROUP) diff --git a/src/sentry/seer/agent/tools.py b/src/sentry/seer/agent/tools.py index 3c644600f53e..a903b7d3d36f 100644 --- a/src/sentry/seer/agent/tools.py +++ b/src/sentry/seer/agent/tools.py @@ -967,7 +967,7 @@ def get_repository_definition( external_id=external_id, status=ObjectStatus.ACTIVE, provider__in=supported_providers, - ).first() + ).first() # noqa: S034 if not repo: parts = repo_full_name.split("/") @@ -983,7 +983,7 @@ def get_repository_definition( name=repo_full_name, status=ObjectStatus.ACTIVE, provider__in=supported_providers, - ).first() + ).first() # noqa: S034 if not repo: logger.info( @@ -2744,7 +2744,7 @@ def get_dsn( organization=organization, status=ObjectStatus.ACTIVE, slug=project_slug, - ).first() + ).first() # noqa: S034 if project is None or not caller_can_access_project(project): return None diff --git a/src/sentry/seer/agentic_triage/delivery.py b/src/sentry/seer/agentic_triage/delivery.py index a1e4821bbe54..a7112be846b6 100644 --- a/src/sentry/seer/agentic_triage/delivery.py +++ b/src/sentry/seer/agentic_triage/delivery.py @@ -148,7 +148,7 @@ def deliver_agentic_triage_result( seer_run__uuid=run_uuid, run__organization_id=organization_id ) .select_related("run", "run__organization", "seer_run") - .first() + .first() # noqa: S034 ) if shard is None: logger.warning( diff --git a/src/sentry/seer/anomaly_detection/delete_rule.py b/src/sentry/seer/anomaly_detection/delete_rule.py index d3efc10feac8..750fb7c05f65 100644 --- a/src/sentry/seer/anomaly_detection/delete_rule.py +++ b/src/sentry/seer/anomaly_detection/delete_rule.py @@ -43,7 +43,7 @@ def delete_data_in_seer_for_detector(detector: Detector) -> None: from sentry.incidents.models.alert_rule import AlertRuleDetectionType from sentry.workflow_engine.models import DataSourceDetector - data_source_detector = DataSourceDetector.objects.filter(detector_id=detector.id).first() + data_source_detector = DataSourceDetector.objects.filter(detector_id=detector.id).first() # noqa: S034 if not data_source_detector: logger.error( "No data source found for detector", diff --git a/src/sentry/seer/anomaly_detection/store_data_workflow_engine.py b/src/sentry/seer/anomaly_detection/store_data_workflow_engine.py index 647e4628195e..66b01bde41a6 100644 --- a/src/sentry/seer/anomaly_detection/store_data_workflow_engine.py +++ b/src/sentry/seer/anomaly_detection/store_data_workflow_engine.py @@ -40,7 +40,7 @@ def _fetch_related_models(detector: Detector, method: str) -> tuple[DataSource, SnubaQuery]: # XXX: it is technically possible (though not used today) that a detector could have multiple data sources - data_source_detector = DataSourceDetector.objects.filter(detector_id=detector.id).first() + data_source_detector = DataSourceDetector.objects.filter(detector_id=detector.id).first() # noqa: S034 if not data_source_detector: raise DetectorException(f"Could not {method} detector, data source not found.") data_source = data_source_detector.data_source diff --git a/src/sentry/seer/autofix/autofix_agent.py b/src/sentry/seer/autofix/autofix_agent.py index 0a803fc4cc36..7ec8ea5d19c4 100644 --- a/src/sentry/seer/autofix/autofix_agent.py +++ b/src/sentry/seer/autofix/autofix_agent.py @@ -281,7 +281,7 @@ def _group_and_referrer_from_run( source__in=(FEATURE_ID, LEGACY_FEATURE_ID), ) .values("group_id", "extras") - .first() + .first() # noqa: S034 ) if run_context is None: return None, None @@ -308,7 +308,7 @@ def resolve_run_group_id( def fetch_run_group(organization: Organization, run_id: int, group_id: int) -> Group | None: """The run's group, scoped to the organization.""" - group = Group.objects.filter(id=group_id, project__organization_id=organization.id).first() + group = Group.objects.filter(id=group_id, project__organization_id=organization.id).first() # noqa: S034 if group is None: logger.warning( "autofix.on_completion_hook.group_not_found", @@ -850,7 +850,7 @@ def trigger_push_changes( seer_run = SeerRun.objects.filter( organization_id=group.organization.id, seer_run_state_id=run_id - ).first() + ).first() # noqa: S034 # Draft when review-request/CI-green is enabled; mark ready once green fires. client.push_changes( diff --git a/src/sentry/seer/autofix/feature/delivery.py b/src/sentry/seer/autofix/feature/delivery.py index a141ed88d083..54578d8ad50c 100644 --- a/src/sentry/seer/autofix/feature/delivery.py +++ b/src/sentry/seer/autofix/feature/delivery.py @@ -41,7 +41,7 @@ def deliver_autofix_feature_result( source__in=(FEATURE_ID, LEGACY_FEATURE_ID, SINGLE_RUN_FEATURE_ID), ) .select_related("run", "run__organization") - .first() + .first() # noqa: S034 ) if agent_run is None: logger.warning( diff --git a/src/sentry/seer/autofix/on_completion_hook.py b/src/sentry/seer/autofix/on_completion_hook.py index bd98d1f4e3fe..a03c0f681971 100644 --- a/src/sentry/seer/autofix/on_completion_hook.py +++ b/src/sentry/seer/autofix/on_completion_hook.py @@ -104,7 +104,7 @@ def _stopping_point_from_run(organization: Organization, run_id: int) -> str | N source__in=(AUTOFIX_FEATURE_ID, LEGACY_AUTOFIX_FEATURE_ID), ) .values_list("extras__stopping_point", flat=True) - .first() + .first() # noqa: S034 ) @@ -239,7 +239,7 @@ def _complete_single_run( return seer_run = SeerRun.objects.filter( organization_id=organization.id, seer_run_state_id=run_id - ).first() + ).first() # noqa: S034 if seer_run is None: logger.warning( "autofix.on_completion_hook.single_run_missing_seer_run", @@ -490,7 +490,7 @@ def _send_step_webhook( seer_run = SeerRun.objects.filter( organization_id=organization.id, seer_run_state_id=run_id, - ).first() + ).first() # noqa: S034 sentry_run_id = str(seer_run.uuid) if seer_run is not None else None webhook_payload: dict[str, object] = { diff --git a/src/sentry/seer/autofix/pr_iteration/cap_exhausted.py b/src/sentry/seer/autofix/pr_iteration/cap_exhausted.py index 3b01727c47d7..815e9f51a28d 100644 --- a/src/sentry/seer/autofix/pr_iteration/cap_exhausted.py +++ b/src/sentry/seer/autofix/pr_iteration/cap_exhausted.py @@ -159,7 +159,7 @@ def assign_user_for_exhausted_cap( seer_run = SeerRun.objects.filter( seer_run_state_id=resolved.run_state.run_id, organization=organization - ).first() + ).first() # noqa: S034 if seer_run is None: # Legacy runs predating SeerRun mirroring have no row to hold the marker. _skip("no_seer_run", log_extra) diff --git a/src/sentry/seer/autofix/pr_iteration/check_suites.py b/src/sentry/seer/autofix/pr_iteration/check_suites.py index 2d139886f042..41813b5088c5 100644 --- a/src/sentry/seer/autofix/pr_iteration/check_suites.py +++ b/src/sentry/seer/autofix/pr_iteration/check_suites.py @@ -522,7 +522,7 @@ def resolve_green_check_suite( seer_run = SeerRun.objects.filter( seer_run_state_id=autofix_run.run_state.run_id, organization=organization - ).first() + ).first() # noqa: S034 if seer_run is None: _skip("no_seer_run", log_extra) return None diff --git a/src/sentry/seer/autofix/pr_iteration/current_iteration.py b/src/sentry/seer/autofix/pr_iteration/current_iteration.py index f236009a8a1a..eb8e82742f9d 100644 --- a/src/sentry/seer/autofix/pr_iteration/current_iteration.py +++ b/src/sentry/seer/autofix/pr_iteration/current_iteration.py @@ -32,7 +32,7 @@ def untriggered_iteration_id(*, run_id: int, organization_id: int) -> int | None try: seer_run = SeerRun.objects.filter( seer_run_state_id=run_id, organization_id=organization_id - ).first() + ).first() # noqa: S034 if seer_run is None: return None diff --git a/src/sentry/seer/autofix/pr_iteration/details_store.py b/src/sentry/seer/autofix/pr_iteration/details_store.py index 48a1b1076f83..5e35dbb75007 100644 --- a/src/sentry/seer/autofix/pr_iteration/details_store.py +++ b/src/sentry/seer/autofix/pr_iteration/details_store.py @@ -14,7 +14,7 @@ def get_iteration(seer_run: SeerRun, iteration_id: int) -> SeerRunPrIteration | None: - return SeerRunPrIteration.objects.filter(seer_run=seer_run, id=iteration_id).first() + return SeerRunPrIteration.objects.filter(seer_run=seer_run, id=iteration_id).first() # noqa: S034 def open_iterations(seer_run: SeerRun) -> list[SeerRunPrIteration]: diff --git a/src/sentry/seer/autofix/pr_iteration/emit.py b/src/sentry/seer/autofix/pr_iteration/emit.py index b93b3a39709d..19cb96272261 100644 --- a/src/sentry/seer/autofix/pr_iteration/emit.py +++ b/src/sentry/seer/autofix/pr_iteration/emit.py @@ -141,7 +141,7 @@ def outcome_for_failed_run(run_state: SeerRunState) -> str: def _seer_run(*, run_id: int, organization_id: int) -> SeerRun | None: - return SeerRun.objects.filter(seer_run_state_id=run_id, organization_id=organization_id).first() + return SeerRun.objects.filter(seer_run_state_id=run_id, organization_id=organization_id).first() # noqa: S034 def _claim_untriggered(seer_run: SeerRun) -> SeerRunPrIteration | None: @@ -179,7 +179,7 @@ def bootstrap_iteration( project_id = ( Group.objects.filter(id=group_id, project__organization_id=organization_id) .values_list("project_id", flat=True) - .first() + .first() # noqa: S034 ) if project_id is None: raise ValueError(f"No group {group_id} in organization {organization_id}") diff --git a/src/sentry/seer/autofix/pr_iteration/missing_permissions.py b/src/sentry/seer/autofix/pr_iteration/missing_permissions.py index 5e1032141d2d..2143a07d4810 100644 --- a/src/sentry/seer/autofix/pr_iteration/missing_permissions.py +++ b/src/sentry/seer/autofix/pr_iteration/missing_permissions.py @@ -324,7 +324,7 @@ def _queue_missing_permissions_comments( ) -> None: from sentry.tasks.seer.pr_iteration import comment_on_missing_permissions - seer_run = SeerRun.objects.filter(seer_run_state_id=run_id, organization=organization).first() + seer_run = SeerRun.objects.filter(seer_run_state_id=run_id, organization=organization).first() # noqa: S034 if seer_run is None: # Legacy runs predating SeerRun mirroring have no row to dedupe # against; staying silent beats commenting on every failing suite. @@ -384,7 +384,7 @@ def post_missing_permissions_comment( "scm_repo_full_name": repo_name, "pr_id": pr_id, } - seer_run = SeerRun.objects.filter(seer_run_state_id=run_id, organization=organization).first() + seer_run = SeerRun.objects.filter(seer_run_state_id=run_id, organization=organization).first() # noqa: S034 if seer_run is None: _skip(log_ctx, "no_seer_run", **log_fields) return diff --git a/src/sentry/seer/autofix/pr_iteration/pause.py b/src/sentry/seer/autofix/pr_iteration/pause.py index fb6b7b8afae4..3bff3fdda843 100644 --- a/src/sentry/seer/autofix/pr_iteration/pause.py +++ b/src/sentry/seer/autofix/pr_iteration/pause.py @@ -32,7 +32,7 @@ class PauseReason(StrEnum): def _get_seer_run(run_id: int, organization_id: int) -> SeerRun | None: - return SeerRun.objects.filter(seer_run_state_id=run_id, organization_id=organization_id).first() + return SeerRun.objects.filter(seer_run_state_id=run_id, organization_id=organization_id).first() # noqa: S034 def record_pause_blocked(gate: str) -> None: diff --git a/src/sentry/seer/autofix/pr_iteration/reviewer_candidates.py b/src/sentry/seer/autofix/pr_iteration/reviewer_candidates.py index 584110dc7cd0..af06e9abbde3 100644 --- a/src/sentry/seer/autofix/pr_iteration/reviewer_candidates.py +++ b/src/sentry/seer/autofix/pr_iteration/reviewer_candidates.py @@ -222,7 +222,7 @@ def _suspect_commit_author_logins(organization: Organization, group_id: int) -> commit = ( Commit.objects.filter(id=group_owner.context["commitId"], organization_id=organization.id) .select_related("author") - .first() + .first() # noqa: S034 ) if commit is not None and commit.author is not None: login = commit.author.get_username_from_external_id() diff --git a/src/sentry/seer/autofix/webhooks.py b/src/sentry/seer/autofix/webhooks.py index 24a15a252185..39e3cb742e43 100644 --- a/src/sentry/seer/autofix/webhooks.py +++ b/src/sentry/seer/autofix/webhooks.py @@ -179,7 +179,7 @@ def _update_autofix_issue_data_for_pr( issue_data = SeerAutofixIssueData.objects.filter( group_id=group_id, organization_id=org.id - ).first() + ).first() # noqa: S034 number = pull_request.get("number") if issue_data is None or number is None: return @@ -266,7 +266,7 @@ def handle_pull_requests_merged_milestone( pull_request__repository_id=repo.id, pull_request__key=str(number), ) - .first() + .first() # noqa: S034 ) if link is None: return diff --git a/src/sentry/seer/code_review/preflight.py b/src/sentry/seer/code_review/preflight.py index 0254cbf1c853..02cc04188990 100644 --- a/src/sentry/seer/code_review/preflight.py +++ b/src/sentry/seer/code_review/preflight.py @@ -55,7 +55,7 @@ def __init__( self.integration = integration self.pr_author_external_id = pr_author_external_id - repo_settings = RepositorySettings.objects.filter(repository=repo).first() + repo_settings = RepositorySettings.objects.filter(repository=repo).first() # noqa: S034 self._repo_settings = repo_settings.get_code_review_settings() if repo_settings else None def check(self) -> CodeReviewPreflightResult: diff --git a/src/sentry/seer/endpoints/organization_seer_agent_chat.py b/src/sentry/seer/endpoints/organization_seer_agent_chat.py index 6f3e87263a81..0a3e704447bc 100644 --- a/src/sentry/seer/endpoints/organization_seer_agent_chat.py +++ b/src/sentry/seer/endpoints/organization_seer_agent_chat.py @@ -243,7 +243,7 @@ def _maybe_reply_to_single_run( group__isnull=False, ) .select_related("run", "group__project") - .first() + .first() # noqa: S034 ) replier = acting_user(request.user) if single_run is None or single_run.group is None or replier is None: diff --git a/src/sentry/seer/endpoints/organization_seer_chat_suggestions.py b/src/sentry/seer/endpoints/organization_seer_chat_suggestions.py index 62d3478f2d8f..68ecfa464d3f 100644 --- a/src/sentry/seer/endpoints/organization_seer_chat_suggestions.py +++ b/src/sentry/seer/endpoints/organization_seer_chat_suggestions.py @@ -196,7 +196,7 @@ def _can_edit_node_type( if dashboard_id := _to_valid_int_id("dashboardId", route_params.get("dashboardId")): dashboard = Dashboard.objects.filter( id=dashboard_id, organization_id=organization.id - ).first() + ).first() # noqa: S034 if dashboard and OrganizationDashboardsPermission().has_object_permission( request, self, dashboard ): @@ -207,7 +207,7 @@ def _can_edit_node_type( id=workflow_id, organization_id=organization.id, type=Workflow.Type.ALERT, - ).first() + ).first() # noqa: S034 if workflow: try: enforce_workflow_access(workflow, organization, request) diff --git a/src/sentry/seer/endpoints/project_seer_repos.py b/src/sentry/seer/endpoints/project_seer_repos.py index c73ecf47abfa..27eaf6259751 100644 --- a/src/sentry/seer/endpoints/project_seer_repos.py +++ b/src/sentry/seer/endpoints/project_seer_repos.py @@ -346,7 +346,7 @@ def get(self, request: Request, project: Project, repo_id: int) -> Response: if is_seer_token_based_billing_onboarding_enabled(project.organization) else _get_seat_based_billing_project_repos(project) ) - project_repo = project_repos_qs.filter(repository_id=repo_id).first() + project_repo = project_repos_qs.filter(repository_id=repo_id).first() # noqa: S034 if project_repo is None: return Response(status=404) diff --git a/src/sentry/seer/endpoints/utils.py b/src/sentry/seer/endpoints/utils.py index 3414c3bd2aba..1aaa0a51230f 100644 --- a/src/sentry/seer/endpoints/utils.py +++ b/src/sentry/seer/endpoints/utils.py @@ -50,7 +50,7 @@ def get_seer_run(seer_run_state_id: int, organization: Organization) -> SeerRun or None when no row exists (legacy runs predating SeerRun mirroring).""" return SeerRun.objects.filter( seer_run_state_id=seer_run_state_id, organization=organization - ).first() + ).first() # noqa: S034 _NO_ACCESS_DETAIL = "You do not have access to this run." @@ -96,7 +96,7 @@ def resolve_seer_run( except (TypeError, ValueError): return Response({"detail": "Invalid run_id"}, status=status.HTTP_400_BAD_REQUEST) - run = SeerRun.objects.filter(uuid=run_uuid, organization=organization).first() + run = SeerRun.objects.filter(uuid=run_uuid, organization=organization).first() # noqa: S034 if run is None: return Response({"session": None}, status=status.HTTP_404_NOT_FOUND) if user_id is not None and run.user_id != user_id: diff --git a/src/sentry/seer/entrypoints/slack/investigation_status.py b/src/sentry/seer/entrypoints/slack/investigation_status.py index 207824db7ab5..9f46bffd071b 100644 --- a/src/sentry/seer/entrypoints/slack/investigation_status.py +++ b/src/sentry/seer/entrypoints/slack/investigation_status.py @@ -277,7 +277,7 @@ def _build_next_step(run: InvestigationOrchestrationRun) -> SeerInvestigationNex producer_revision=_report_revision(run), primary=True, state__in=LIVE_STATES, - ).first() + ).first() # noqa: S034 if request is None: return None return SeerInvestigationNextStep( diff --git a/src/sentry/seer/fetch_issues/utils.py b/src/sentry/seer/fetch_issues/utils.py index 916263e8d7de..66839041b3d0 100644 --- a/src/sentry/seer/fetch_issues/utils.py +++ b/src/sentry/seer/fetch_issues/utils.py @@ -182,7 +182,7 @@ def get_latest_issue_event( else: group = Group.objects.filter( id=int(group_id), project__organization_id=organization_id - ).first() + ).first() # noqa: S034 if not group or not caller_can_access_project(group.project): logger.warning( diff --git a/src/sentry/seer/similarity/similar_issues.py b/src/sentry/seer/similarity/similar_issues.py index 5ca346b4a6aa..2c190ab8e42b 100644 --- a/src/sentry/seer/similarity/similar_issues.py +++ b/src/sentry/seer/similarity/similar_issues.py @@ -255,7 +255,7 @@ def get_similarity_data_from_seer( grouphash__project_id=project_id, grouphash__hash=parent_hash ) .values_list("date_added", flat=True) - .first() + .first() # noqa: S034 ) if parent_grouphash_date_added: @@ -302,7 +302,7 @@ def get_similarity_data_from_seer( grouphash__project_id=project_id, grouphash__hash=parent_hash ) .values_list("date_added", flat=True) - .first() + .first() # noqa: S034 ) if parent_grouphash_date_added: diff --git a/src/sentry/seer/similarity/types.py b/src/sentry/seer/similarity/types.py index 9e5f62260ae2..a1a83f115ebf 100644 --- a/src/sentry/seer/similarity/types.py +++ b/src/sentry/seer/similarity/types.py @@ -105,7 +105,7 @@ def from_raw(cls, project_id: int, raw_similar_issue_data: Mapping[str, Any]) -> project_id=project_id, hash=raw_similar_issue_data["parent_hash"] ) .exclude(state=GroupHash.State.LOCKED_IN_MIGRATION) - .first() + .first() # noqa: S034 ) if not parent_grouphash: diff --git a/src/sentry/seer/smart_assignment/completion.py b/src/sentry/seer/smart_assignment/completion.py index d32f50eee9d6..a5d86f9a697e 100644 --- a/src/sentry/seer/smart_assignment/completion.py +++ b/src/sentry/seer/smart_assignment/completion.py @@ -26,7 +26,7 @@ def process_smart_assignment_completion(group: Group, activity: Activity) -> Non seer_run_id = data.get("run_id") run = ( - SeerAgentRun.objects.filter(run_id=seer_run_id).first() if seer_run_id is not None else None + SeerAgentRun.objects.filter(run_id=seer_run_id).first() if seer_run_id is not None else None # noqa: S034 ) # We need someone who actually resolves to a Sentry user, so pick one further # down the list of suggestions if necessary. diff --git a/src/sentry/seer/smart_assignment/delivery.py b/src/sentry/seer/smart_assignment/delivery.py index d4ac11be3c36..0fc1027fa006 100644 --- a/src/sentry/seer/smart_assignment/delivery.py +++ b/src/sentry/seer/smart_assignment/delivery.py @@ -44,7 +44,7 @@ def _validate_run( run__uuid=run_uuid, run__organization_id=organization_id, source=SEER_FEATURE_ID ) .select_related("run") - .first() + .first() # noqa: S034 ) if agent_run is None: _incr("missing_run") @@ -89,7 +89,7 @@ def _validate_group(organization_id: int, run_uuid: UUID) -> Group: seeragentrun__run__uuid=run_uuid, seeragentrun__source=SEER_FEATURE_ID, project__organization_id=organization_id, - ).first() + ).first() # noqa: S034 if group is None: _incr("missing_group") logger.warning( diff --git a/src/sentry/seer/smart_assignment/scoring.py b/src/sentry/seer/smart_assignment/scoring.py index 2e81081f94f3..da900623f2db 100644 --- a/src/sentry/seer/smart_assignment/scoring.py +++ b/src/sentry/seer/smart_assignment/scoring.py @@ -136,7 +136,7 @@ def _assignment_updates(group: Group) -> RunUpdates | None: """Mirror the current assignee (user and/or team), or ``None`` when the group has no assignee or the assignment is one we can't grade a prediction against. """ - assignee = GroupAssignee.objects.filter(group=group).first() + assignee = GroupAssignee.objects.filter(group=group).first() # noqa: S034 if assignee is None: return None if _has_unscorable_assignment(group): @@ -167,7 +167,7 @@ def _apply(run_id: int, updates: RunUpdates) -> bool: persisted -- ``False`` when the row is already a terminal snapshot.""" with transaction.atomic(using=router.db_for_write(SeerAgentRun)): run = ( - SeerAgentRun.objects.select_for_update().select_related("run").filter(id=run_id).first() + SeerAgentRun.objects.select_for_update().select_related("run").filter(id=run_id).first() # noqa: S034 ) if run is None: return False diff --git a/src/sentry/seer/workflows/action.py b/src/sentry/seer/workflows/action.py index 537250e89e6c..ecb7bb68ab49 100644 --- a/src/sentry/seer/workflows/action.py +++ b/src/sentry/seer/workflows/action.py @@ -46,7 +46,7 @@ def execute(invocation: ActionInvocation) -> None: binding = SeerWorkflowTriggerBinding.objects.filter( workflow_config__organization_id=group.project.organization_id, trigger_action=invocation.action, - ).first() + ).first() # noqa: S034 if binding is None: _record_trigger_outcome("ignored", extra, reason="missing_binding") return diff --git a/src/sentry/seer/workflows/breached_metrics.py b/src/sentry/seer/workflows/breached_metrics.py index 2829584f78d8..17ce5c5d2e61 100644 --- a/src/sentry/seer/workflows/breached_metrics.py +++ b/src/sentry/seer/workflows/breached_metrics.py @@ -257,7 +257,7 @@ def delete(self) -> None: if config.backing_workflow_id is not None: workflow = Workflow.objects_for_deletion.filter( id=config.backing_workflow_id, organization_id=self.organization_id - ).first() + ).first() # noqa: S034 if workflow is not None and workflow.status == ObjectStatus.ACTIVE: CellScheduledDeletion.schedule(workflow, days=0) workflow.update(status=ObjectStatus.PENDING_DELETION) @@ -326,7 +326,7 @@ def _record_run( strategy=SeerWorkflowStrategy.BREACHED_METRIC_INVESTIGATION, enabled=True, ) - .first() + .first() # noqa: S034 ) if config is None: return IgnoredMetricBreach("configuration_unavailable") diff --git a/src/sentry/seer/workflows/runs.py b/src/sentry/seer/workflows/runs.py index 7f8354ccf338..a67e96066f12 100644 --- a/src/sentry/seer/workflows/runs.py +++ b/src/sentry/seer/workflows/runs.py @@ -277,7 +277,7 @@ def deliver_workflow_result( agent_run = ( SeerAgentRun.objects.select_related("run__organization") .filter(run__organization_id=organization_id, source=feature_id, run__uuid=run_uuid) - .first() + .first() # noqa: S034 ) if agent_run is None: logger.warning("seer.workflow.delivery.missing_run", extra=log_extra) @@ -321,7 +321,7 @@ def finish_workflow_run( agent_run = ( SeerAgentRun.objects.select_for_update(of=("self",)) .filter(run_id=run_id, run__organization_id=organization_id, source=feature_id) - .first() + .first() # noqa: S034 ) if agent_run is None or agent_run.extras.get("status") in TERMINAL_STATUSES: return