Skip to content

Commit

Permalink
ref: fix typing for sentry.profiles (#72816)
Browse files Browse the repository at this point in the history
fixes errors when BaseManager becomes typechecked

<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Jun 14, 2024
1 parent ba80ae9 commit dcfbb50
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/sentry/profiles/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime, timezone
from functools import lru_cache
from time import time
from typing import Any
from typing import Any, TypedDict
from uuid import UUID

import msgpack
Expand Down Expand Up @@ -1062,14 +1062,21 @@ def clean_android_js_profile(profile: Profile) -> None:
del p["dist"]


class _ProjectKeyKwargs(TypedDict):
project_id: int
use_case: str


@lru_cache(maxsize=100)
def get_metrics_dsn(project_id: int) -> str:
kwargs = dict(project_id=project_id, use_case=UseCase.PROFILING.value)
kwargs: _ProjectKeyKwargs = {"project_id": project_id, "use_case": UseCase.PROFILING.value}
try:
project_key, _ = ProjectKey.objects.get_or_create(**kwargs)
except ProjectKey.MultipleObjectsReturned:
# See https://docs.djangoproject.com/en/5.0/ref/models/querysets/#get-or-create
project_key = ProjectKey.objects.filter(**kwargs).order_by("pk").first()
project_key_first = ProjectKey.objects.filter(**kwargs).order_by("pk").first()
assert project_key_first is not None
project_key = project_key_first
return project_key.get_dsn(public=True)


Expand Down

0 comments on commit dcfbb50

Please sign in to comment.