Add generic support for rate limiting.
Review Request #14631 — Created Oct. 8, 2025 and updated
Djblets has long had rate limiting support for user sessions, allowing
separate rate limits for anonymous users and authenticated users for
normal sessions and API. Outside of this, though, we had no mechanism
for rate limiting other operations.This change introduces that generic rate limiting support via a new
djblets.protect.ratelimitmodule. This is a modernized port of the old
rate limit code, which can be used with arbitrary keys and validity
windows to provide rate limit functionality for anything.The main function is
check_rate_limit, which takes in a parsed or
string rate limit, a partial cache key, and a flag indicating whether to
increment the count toward the rate limit in cache (defaults toTrue).The existing auth rate limiting code has been reworked as a wrapper
around this, focusing on the settings and checks for rate limiting
user sessions.
Unit tests pass.
| Summary | ID |
|---|---|
| 7f8c2b3f4589007a21864b0e5935cb677bdf2b28 |
| Description | From | Last Updated |
|---|---|---|
|
djblets.http.requests doesn't currently exist. Did you forget to add this file? |
|
|
|
Can we use .format() instead of %-formatting here? |
|
|
|
This type is wrong |
|
|
|
Can we pass the timeout as a kwarg here? |
|
|
|
too many blank lines (2) Column: 9 Error code: E303 |
|
|
|
Can Any be imported inside of TYPE_CHECKING? |
|
|
|
Can you add ValueError and ImproperlyConfigured to a Raises section in the docs here. |
|
|
|
Can you add ValueError to a Raises section in the docs here. |
|
|
|
This should say list of str and mention the user_id_or_ip part of the return value. |
|
|
|
This needs a Raises section for ValueError. |
|
|
|
This should say rate_limit instead of default_limit. |
|
|
|
We should maybe mention this in the arg description for rate_limit, that it can be set to None for no … |
|
- Change Summary:
-
- Switched to
.format()for a string. - Fixed a type in docs.
- Fixed an old moved
cache.add()call to explicitly pass the timeout as a keyword argument.
- Switched to
- Commits:
-
Summary ID 272beaa42c350a1093d5f639a49a09c0ae5b6fc0 fa9944b879bf157cded9d9109277128bf483a135
Checks run (2 succeeded)
- Change Summary:
-
- Added missing exception documentation to several functions.
- Fixed the return docs for the old
is_ratelimited(). - Fixed an incorrect argument name in the
check_rate_limit()docs and described theNonecase for the value.
- Commits:
-
Summary ID fa9944b879bf157cded9d9109277128bf483a135 7f8c2b3f4589007a21864b0e5935cb677bdf2b28