diff --git a/src/sentry/models/release.py b/src/sentry/models/release.py index c46815aff0740..8203d575b71bd 100644 --- a/src/sentry/models/release.py +++ b/src/sentry/models/release.py @@ -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): diff --git a/src/sentry/models/releases/util.py b/src/sentry/models/releases/util.py index 5c93f1435b5ea..b0d86ebfd60d6 100644 --- a/src/sentry/models/releases/util.py +++ b/src/sentry/models/releases/util.py @@ -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 @@ -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__) @@ -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 @@ -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. @@ -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 @@ -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 @@ -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