Skip to content

Commit

Permalink
ref: adjust typing so rate_limits can be a callable
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile-sentry committed Jul 23, 2024
1 parent 7f1026a commit 4441a66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/sentry/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ class Endpoint(APIView):

owner: ApiOwner = ApiOwner.UNOWNED
publish_status: dict[HTTP_METHOD_NAME, ApiPublishStatus] = {}
rate_limits: RateLimitConfig | dict[
str, dict[RateLimitCategory, RateLimit]
rate_limits: RateLimitConfig | dict[str, dict[RateLimitCategory, RateLimit]] | Callable[
..., RateLimitConfig | dict[str, dict[RateLimitCategory, RateLimit]]
] = DEFAULT_RATE_LIMIT_CONFIG
enforce_rate_limit: bool = settings.SENTRY_RATELIMITER_ENABLED
snuba_methods: list[HTTP_METHOD_NAME] = []
Expand Down
3 changes: 2 additions & 1 deletion tests/sentry/middleware/test_ratelimit_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ class CallableRateLimitConfigEndpoint(Endpoint):
permission_classes = (AllowAny,)
enforce_rate_limit = True

def rate_limits(request):
@staticmethod
def rate_limits(*a, **k):
return {
"GET": {
RateLimitCategory.IP: RateLimit(limit=20, window=1),
Expand Down

0 comments on commit 4441a66

Please sign in to comment.