Skip to content

Commit 855a957

Browse files
committed
fix(cleanup): Use correct expiration thresholds for API model cleanup
- Update delete_api_models to use model-specific DEFAULT_EXPIRATION values - Use API_GRANT_EXPIRATION for ApiGrant and API_TOKEN_EXPIRATION for ApiToken - Fix potential over-deletion of valid tokens
1 parent b3a8ada commit 855a957

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/sentry/runner/commands/cleanup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ def remove_expired_values_for_org_members(
316316

317317

318318
def delete_api_models(is_filtered: Callable[[type[Model]], bool]) -> None:
319+
from sentry.models.apigrant import DEFAULT_EXPIRATION as API_GRANT_EXPIRATION
319320
from sentry.models.apigrant import ApiGrant
321+
from sentry.models.apitoken import DEFAULT_EXPIRATION as API_TOKEN_EXPIRATION
320322
from sentry.models.apitoken import ApiToken
321323

322324
for model_tp in (ApiGrant, ApiToken):
@@ -325,8 +327,11 @@ def delete_api_models(is_filtered: Callable[[type[Model]], bool]) -> None:
325327
if is_filtered(model_tp):
326328
debug_output(f">> Skipping {model_tp.__name__}")
327329
else:
330+
expiration_threshold = (
331+
API_GRANT_EXPIRATION if model_tp is ApiGrant else API_TOKEN_EXPIRATION
332+
)
328333
queryset = model_tp.objects.filter(
329-
expires_at__lt=(timezone.now() - timedelta(days=API_TOKEN_TTL_IN_DAYS))
334+
expires_at__lt=(timezone.now() - expiration_threshold)
330335
)
331336

332337
# SentryAppInstallations are associated to ApiTokens. We're okay

0 commit comments

Comments
 (0)