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
2 changes: 1 addition & 1 deletion src/sentry/api/bases/organizationmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _get_member(

om_id = kwargs.get("id")
if isinstance(om_id, int):
invite = OrganizationMemberInvite.objects.filter(organization_member_id=om_id).first()
invite = OrganizationMemberInvite.objects.filter(organization_member_id=om_id).first() # noqa: S034
if invite is not None:
raise ResourceDoesNotExist

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/api_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def delete(self, request: Request) -> Response[dict[str, object] | None]:
with outbox_context(transaction.atomic(router.db_for_write(ApiToken)), flush=False):
token_to_delete: ApiToken | None = ApiToken.objects.filter(
id=token_id, application__isnull=True, user_id=user_id
).first()
).first() # noqa: S034

if token_to_delete is None:
return Response({"tokenId": token_id, "userId": user_id}, status=400)
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/endpoints/artifact_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def download_file(self, download_id: str, project: Project) -> HttpResponseBase:
projectartifactbundle__project_id=project.id,
)
.select_related("file")
.first()
.first() # noqa: S034
)
metrics.incr("sourcemaps.download.artifact_bundle")
elif ty == "release_file":
Expand All @@ -104,7 +104,7 @@ def download_file(self, download_id: str, project: Project) -> HttpResponseBase:
organization_id=project.organization.id,
)
.select_related("file")
.first()
.first() # noqa: S034
)
if (
file_m is not None
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/endpoints/auth_organization_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def get(self, request: Request, organization_id_or_slug: str) -> Response:
raise NotFound()

organization = organization_context.organization
auth_provider = AuthProvider.objects.filter(organization_id=organization.id).first()
avatar = OrganizationAvatarReplica.objects.filter(organization_id=organization.id).first()
auth_provider = AuthProvider.objects.filter(organization_id=organization.id).first() # noqa: S034
avatar = OrganizationAvatarReplica.objects.filter(organization_id=organization.id).first() # noqa: S034
is_demo_organization = is_demo_mode_enabled() and is_demo_org(organization)

provider = None
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/api/endpoints/auth_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get(self, request: Request) -> Response:
user_id=serializer.validated_data["user_id"],
hash=serializer.validated_data["token"],
)
.first()
.first() # noqa: S034
)
valid = bool(
password_hash is not None
Expand Down Expand Up @@ -164,7 +164,7 @@ def post(self, request: Request) -> Response:
password_hash = (
LostPasswordHash.objects.select_related("user")
.filter(user_id=user_id, hash=token)
.first()
.first() # noqa: S034
)
if password_hash is None:
return Response({"detail": "Invalid or expired recovery token"}, status=400)
Expand All @@ -188,7 +188,7 @@ def post(self, request: Request) -> Response:
LostPasswordHash.objects.select_for_update()
.select_related("user")
.filter(user_id=user_id, hash=token)
.first()
.first() # noqa: S034
)
if password_hash is None:
return Response({"detail": "Invalid or expired recovery token"}, status=400)
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/endpoints/debug_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def download(

debug_file = ProjectDebugFile.objects.filter(
id=debug_file_id, project_id=project.id
).first()
).first() # noqa: S034

if debug_file is None:
raise Http404
Expand Down Expand Up @@ -520,7 +520,7 @@ def delete(self, request: Request, project: Project) -> Response:
debug_file = (
ProjectDebugFile.objects.filter(id=validated_id, project_id=project.id)
.select_related("file")
.first()
.first() # noqa: S034
)
if debug_file is not None:
debug_file.delete()
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/organization_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def post(self, request: Request, organization_id_or_slug: str) -> Response:
provenance=Relocation.Provenance.SAAS_TO_SAAS.value,
want_org_slugs=[org_mapping.slug],
status__in={Relocation.Status.IN_PROGRESS.value, Relocation.Status.PAUSE.value},
).first()
).first() # noqa: S034
if duplicate_relocation is not None:
return Response(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def put(
identity__idp__type=provider_key,
)
.select_related("identity")
.first()
.first() # noqa: S034
)
if org_identity is None:
return Response({"detail": "Not connected to this provider."}, status=404)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/source_map_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def _get_dist_matched_artifact_index_release_file(self) -> ReleaseFile | None:
file__type=ARTIFACT_INDEX_TYPE,
)
.select_related("file")
.first()
.first() # noqa: S034
)
if self.dist_matched_artifact_index_release_file:
maybe_renew_releasefiles([self.dist_matched_artifact_index_release_file])
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/helpers/group_index/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_current_release_version_of_group(group: Group, follows_semver: bool = Fa
current_release_version = (
Release.objects.filter(id__in=latest_observation)
.values_list("version", flat=True)
.first()
.first() # noqa: S034
)
return current_release_version

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/apitoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def write_relocation_import(
query = models.Q(token=self.token) | models.Q(
refresh_token__isnull=False, refresh_token=self.refresh_token
)
existing = self.__class__.objects.filter(query).first()
existing = self.__class__.objects.filter(query).first() # noqa: S034
if existing:
self.token = generate_token(token_type=self.token_type)
if self.refresh_token is not None:
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_favorite_dashboard(
"""
return self.filter(
organization=organization, user_id=user_id, dashboard=dashboard, favorited=True
).first()
).first() # noqa: S034

def reorder_favorite_dashboards(
self, organization: Organization, user_id: int, new_dashboard_positions: list[int]
Expand Down Expand Up @@ -175,7 +175,7 @@ def insert_favorite_dashboard(
dashboard=dashboard,
)
.select_for_update()
.first()
.first() # noqa: S034
)

if existing and existing.favorited:
Expand Down Expand Up @@ -221,7 +221,7 @@ def insert_favorite_dashboard_alphabetically(
dashboard=dashboard,
)
.select_for_update()
.first()
.first() # noqa: S034
)

if existing and existing.favorited:
Expand Down Expand Up @@ -471,7 +471,7 @@ def favorited_by(self, user_ids: Iterable[int]) -> None:
users_to_refavorite = new_user_ids & existing_user_ids

for user_id in users_to_refavorite:
fav = existing_favorites.filter(user_id=user_id, favorited=False).first()
fav = existing_favorites.filter(user_id=user_id, favorited=False).first() # noqa: S034
if fav:
last_position = DashboardFavoriteUser.objects.get_last_position(
self.organization, user_id
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/featureadoption.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def bulk_record(
def get_by_slug(self, organization: Organization, slug: str) -> FeatureAdoption | None:
return self.filter(
organization=organization, feature_id=manager.get_by_slug(slug).id
).first()
).first() # noqa: S034


@cell_silo_model
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/groupopenperiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def create_open_period(group: Group, start_time: datetime, event_id: str | None
with transaction.atomic(router.db_for_write(Group)):
# Force a Group lock before the create to establish consistent lock ordering
# This prevents deadlocks by ensuring we always acquire the Group lock first
Group.objects.select_for_update().filter(id=group.id).first()
Group.objects.select_for_update().filter(id=group.id).first() # noqa: S034

# There are some historical cases where we log multiple regressions for the same group,
# but we only want to create a new open period for the first regression
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/groupsearchviewstarred.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_starred_view(
"""
return self.filter(
organization=organization, user_id=user_id, group_search_view=view
).first()
).first() # noqa: S034

def reorder_starred_views(
self, organization: Organization, user_id: int, new_view_positions: list[int]
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/models/organizationmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def save(
update_fields: Iterable[str] | None = None,
) -> None:
if self.id is not None:
invite = OrganizationMemberInvite.objects.filter(organization_member_id=self.id).first()
invite = OrganizationMemberInvite.objects.filter(organization_member_id=self.id).first() # noqa: S034
assert invite is None, "Cannot save placeholder organization member for an invited user"

with outbox_context(transaction.atomic(using=router.db_for_write(OrganizationMember))):
Expand Down Expand Up @@ -753,7 +753,7 @@ def normalize_before_relocation_import(
self.inviter_id = None

# If there is a token collision, just wipe the token. The user can always make a new one.
matching_token = self.__class__.objects.filter(token=self.token).first()
matching_token = self.__class__.objects.filter(token=self.token).first() # noqa: S034
if matching_token is not None:
self.token = None
self.token_expires_at = None
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/organizationmemberinvite.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def write_relocation_import(
) -> tuple[int, ImportKind] | None:
# If there is a token collision, generate new tokens.
query = models.Q(token=self.token)
existing = self.__class__.objects.filter(query).first()
existing = self.__class__.objects.filter(query).first() # noqa: S034
if existing:
self.pk = existing.pk
self.expires_at = timezone.now() + timedelta(days=INVITE_DAYS_VALID)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/orgauthtoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def normalize_before_relocation_import(
# one.
matching_token_hashed = self.__class__.objects.filter(
token_hashed=self.token_hashed
).first()
).first() # noqa: S034
if (not self.token_hashed) or matching_token_hashed:
org_slug = pk_map.get_slug(get_model_name(Organization), self.organization_id)
if org_slug is None:
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/models/projectkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def get_default(cls, project: Project | int) -> ProjectKey | None:
project=project,
roles=models.F("roles").bitor(cls.roles.store),
status=ProjectKeyStatus.ACTIVE,
).first()
).first() # noqa: S034

@property
def is_active(self) -> bool:
Expand Down Expand Up @@ -392,10 +392,10 @@ def write_relocation_import(
self, _s: ImportScope, _f: ImportFlags
) -> tuple[int, ImportKind] | None:
# If there is a key collision, generate new keys.
matching_public_key = self.__class__.objects.filter(public_key=self.public_key).first()
matching_public_key = self.__class__.objects.filter(public_key=self.public_key).first() # noqa: S034
if not self.public_key or matching_public_key:
self.public_key = self.generate_api_key()
matching_secret_key = self.__class__.objects.filter(secret_key=self.secret_key).first()
matching_secret_key = self.__class__.objects.filter(secret_key=self.secret_key).first() # noqa: S034
if not self.secret_key or matching_secret_key:
self.secret_key = self.generate_api_key()

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/pullrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def get_or_fetch_external_id(
organization_id=organization_id,
repository_id=repository_id,
key=key,
).first()
).first() # noqa: S034
if stored is not None and stored.external_id is not None:
metrics.incr(
"scm.pull_request.external_id",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def _get_or_create_impl(
release = cls.objects.filter(
organization_id=project.organization_id,
version__in=[version, project_version],
).first()
).first() # noqa: S034
if release is None:
metric_tags["cache_hit"] = "false"
metric_tags[DATA_ACCESS_TAG] = DataAccessTagValues.DB_READ.value
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/tasks/on_demand_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _get_widget_on_demand_specs(
if not cache.has_key(_get_project_for_query_cache_key(organization)):
# This can just be the first project we find, since spec hashes should not be project
# dependent. If spec hashes become project dependent then this may need to change.
project_for_query = Project.objects.filter(organization=organization).first()
project_for_query = Project.objects.filter(organization=organization).first() # noqa: S034
cache.set(
_get_project_for_query_cache_key(organization),
project_for_query,
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/tasks/seer/agentic_triage/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def run_agentic_triage_for_org(
block on it. The run record, if created, is created synchronously."""
organization = Organization.objects.filter(
id=organization_id, status=OrganizationStatus.ACTIVE
).first()
).first() # noqa: S034
if organization is None:
return None

Expand All @@ -357,7 +357,7 @@ def run_agentic_triage_for_org(
organization=organization,
workflow_config__strategy=SeerWorkflowStrategy.AGENTIC_TRIAGE,
trigger_key=schedule_id,
).first()
).first() # noqa: S034
# Without quota, only completed runs or runs with persisted executions can continue.
if existing_run is None or (
existing_run.date_completed is None and not existing_run.executions.exists()
Expand Down Expand Up @@ -440,7 +440,7 @@ def run_agentic_triage_execution(
"""Heavy phase of an agentic triage run: eligibility, triage, and optional
autofix dispatch. Single code path used by both sync invocation (from
run_agentic_triage_for_org) and async dispatch (apply_async)."""
run = SeerWorkflowRun.objects.select_related("organization").filter(id=run_id).first()
run = SeerWorkflowRun.objects.select_related("organization").filter(id=run_id).first() # noqa: S034
if run is None:
logger.info("night_shift.missing_run", extra={"night_shift_run_id": run_id})
return None
Expand Down Expand Up @@ -600,7 +600,7 @@ def build_run_options(
if org_tweaks is not None:
layered.update(_tweaks_to_partial(org_tweaks))
if project_id is not None:
project = Project.objects.filter(id=project_id, organization_id=organization_id).first()
project = Project.objects.filter(id=project_id, organization_id=organization_id).first() # noqa: S034
if project is not None:
layered.update(_tweaks_to_partial(get_agentic_triage_tweaks(project)))
layered.update(manual_overrides or {})
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/tasks/seer/autofix_issue_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def schedule_judging() -> None:
processing_deadline_duration=5 * 60,
)
def schedule_judging_for_org(organization_id: int, *args: Any, **kwargs: Any) -> None:
organization = Organization.objects.filter(id=organization_id).first()
organization = Organization.objects.filter(id=organization_id).first() # noqa: S034
if organization is None or not features.has(FEATURE_FLAG, organization):
return

Expand Down Expand Up @@ -143,7 +143,7 @@ def judge_issue_data(issues: list[tuple[int, str]], *args: Any, **kwargs: Any) -

def _judge_issue(issue_data_id: int, event_id: str) -> None:
issue_data = (
SeerAutofixIssueData.objects.select_related("organization").filter(id=issue_data_id).first()
SeerAutofixIssueData.objects.select_related("organization").filter(id=issue_data_id).first() # noqa: S034
)
if issue_data is None or not features.has(FEATURE_FLAG, issue_data.organization):
return
Expand Down
Loading
Loading