-
-
Notifications
You must be signed in to change notification settings - Fork 982
Backend: Cache leaderboard endpoint responses to reduce slow DB query #5075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akanshajain231999
wants to merge
5
commits into
Cloud-CV:master
Choose a base branch
from
akanshajain231999:sentry-fix2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
108bf0e
Backend: Cache leaderboard endpoint responses to reduce slow DB query
akanshajain231999 5510b67
Backend: Apply black formatting to leaderboard cache tests
akanshajain231999 61726c0
Merge branch 'master' into sentry-fix2
RishabhJain2018 f1e105a
Merge branch 'master' into sentry-fix2
RishabhJain2018 58c467e
Merge branch 'master' into sentry-fix2
RishabhJain2018 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In Django's Memcached cache backend, what key length/character restrictions apply, and when is InvalidCacheKey raised?💡 Result:
In Django’s Memcached cache backend, the key restrictions and the error behavior are: 1) Key length and character restrictions (memcached-safe) - Maximum key length: keys longer than 250 characters are considered invalid for memcached by Django’s validation logic. [1][2] - Disallowed characters: Django treats keys containing whitespace or control characters (and also DEL/control chars in the range \x00-\x20 and \x7f) as invalid for memcached. [2][1] These checks are applied through Django’s common memcached key warning/validation helpers. Django’s docs explicitly state that memcached keys “does not allow cache keys longer than 250 characters or containing whitespace or control characters”. [2] 2) When InvalidCacheKey is raised - In Django’s memcached backend implementation (MemcachedCache), validate_key iterates over memcache_key_warnings(key) and raises InvalidCacheKey(warning) when any warning is produced. [3] - The warnings are produced specifically when the key violates the above rules (length > 250, or disallowed characters). [1] - Therefore, InvalidCacheKey is raised when you call cache operations on a memcached backend with a key that would violate those memcached constraints (length/whitespace/control chars). This happens during key preparation for backend calls via make_and_validate_key. [3][1] Concretely, calls like cache.get/add/set/touch on the memcached backend will raise InvalidCacheKey if make_and_validate_key(key) detects a memcached-incompatible key. [3][1]
Citations:
🏁 Script executed:
Repository: Cloud-CV/EvalAI
Length of output: 2554
🏁 Script executed:
Repository: Cloud-CV/EvalAI
Length of output: 3870
🏁 Script executed:
Repository: Cloud-CV/EvalAI
Length of output: 7223
🏁 Script executed:
Repository: Cloud-CV/EvalAI
Length of output: 491
🏁 Script executed:
Repository: Cloud-CV/EvalAI
Length of output: 15869
Don’t embed raw
order_byquery param into the Memcached cache keyapps/jobs/views.py(leaderboard, lines 644-647) buildscache_keydirectly fromrequest.GET.get("order_by")(with only a"default"fallback). Even thoughcalculate_distinct_sorted_leaderboard_data()later whitelistsorder_byagainstleaderboard.schema["labels"]for the computation, the cache key itself is still composed from the raw input. With the Memcached cache backend, Django raisesInvalidCacheKeyfor keys that are too long (>250 chars) or contain whitespace/control characters, and there’s no exception handling aroundcache.get()/cache.set(), so this can surface as a 500.Proposed fix
🤖 Prompt for AI Agents