Skip to content

ref: annotate query type for ReleaseQuerySet #73595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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/models/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _get_cache_key(project_id: int, group_id: int, first: bool) -> str:


class ReleaseModelManager(BaseManager["Release"]):
def get_queryset(self):
def get_queryset(self) -> ReleaseQuerySet:
return ReleaseQuerySet(self.model, using=self._db)

def annotate_prerelease_column(self):
Expand Down
16 changes: 10 additions & 6 deletions src/sentry/models/releases/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections import namedtuple
from collections.abc import Sequence
from dataclasses import dataclass
from typing import TYPE_CHECKING, Self

from django.db import models
from django.db.models import Case, F, Func, Q, Subquery, Value, When
Expand All @@ -17,6 +18,9 @@
from sentry.models.releases.release_project import ReleaseProject
from sentry.utils.numbers import validate_bigint

if TYPE_CHECKING:
from sentry.models.release import Release # noqa: F401

logger = logging.getLogger(__name__)


Expand All @@ -34,7 +38,7 @@ class SemverFilter:
negated: bool = False


class ReleaseQuerySet(BaseQuerySet):
class ReleaseQuerySet(BaseQuerySet["Release"]):
def annotate_prerelease_column(self):
"""
Adds a `prerelease_case` column to the queryset which is used to properly sort
Expand All @@ -47,7 +51,7 @@ def annotate_prerelease_column(self):
)
)

def filter_to_semver(self):
def filter_to_semver(self) -> Self:
"""
Filters the queryset to only include semver compatible rows
"""
Expand All @@ -60,7 +64,7 @@ def filter_by_semver_build(
build: str,
project_ids: Sequence[int] | None = None,
negated: bool = False,
) -> models.QuerySet:
) -> Self:
"""
Filters released by build. If the passed `build` is a numeric string, we'll filter on
`build_number` and make use of the passed operator.
Expand Down Expand Up @@ -92,7 +96,7 @@ def filter_by_semver(
organization_id: int,
semver_filter: SemverFilter,
project_ids: Sequence[int] | None = None,
) -> models.QuerySet:
) -> Self:
"""
Filters releases based on a based `SemverFilter` instance.
`SemverFilter.version_parts` can contain up to 6 components, which should map
Expand Down Expand Up @@ -138,7 +142,7 @@ def filter_by_stage(
value,
project_ids: Sequence[int] | None = None,
environments: list[str] | None = None,
) -> models.QuerySet:
) -> Self:
from sentry.models.releaseprojectenvironment import ReleaseProjectEnvironment, ReleaseStages
from sentry.search.events.filter import to_list

Expand Down Expand Up @@ -176,7 +180,7 @@ def filter_by_stage(
qs = self.filter(id__in=Subquery(rpes.filter(query).values_list("release_id", flat=True)))
return qs

def order_by_recent(self):
def order_by_recent(self) -> Self:
return self.order_by("-date_added", "-id")

@staticmethod
Expand Down
Loading