fix(quota_session): _build_limiter — pass rates list as single arg, not unpacked#14
Open
prezis wants to merge 1 commit into
Open
fix(quota_session): _build_limiter — pass rates list as single arg, not unpacked#14prezis wants to merge 1 commit into
prezis wants to merge 1 commit into
Conversation
…ot unpacked pyrate-limiter's Limiter(arg) takes a SINGLE positional arg (Rate or List[Rate]). The previous Limiter(*rates) unpacking silently dropped the daily-budget Rate, leaving only the per-minute rate enforced. Verified by inspecting bucket_factory.get_buckets()[0].rates after fix — both 60/60000ms and 800/86400000ms rates present. Discovered by wojak-wojtek s37 day 6 dispatch when adopting QuotaSession across 4 Finnhub fetchers (60/min + 800/day budget) — daily limit was not firing in production. Adds 3 regression tests in test_quota_session.py that capture Limiter constructor args via a fake module to lock in the single-arg contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug
scraperx.quota_session._build_limitercallsLimiter(*rates)(unpacked), but pyrate-limiter'sLimiter(arg)takes a SINGLE positional arg — either aRateor aList[Rate]. The unpacking silently drops every rate after the first.For a typical caller like
QuotaSession(rates=[Rate(60, Duration.MINUTE), Rate(800, Duration.DAY)]), only the per-minute Rate is enforced; the daily-budget Rate is dropped — daily quota is silently unprotected.Fix
Pass the list as a single arg:
The single-rate fast-path is unchanged.
Verification
After fix:
Both rates are now enforced.
Tests
Adds 3 regression tests in
tests/test_quota_session.pythat swap in a fakepyrate_limitermodule and capture the constructor args:test_build_limiter_passes_multi_rate_list_as_single_arg— locks in the single-arg contract; will fire if the unpacking regression returns.test_build_limiter_passes_single_rate_directly— guards the single-rate fast-path.test_build_limiter_returns_none_for_empty_rates— empty-rates short-circuit.All 12 quota_session tests pass; full wayback suite still 16/16.
Origin
Discovered by wojak-wojtek s37 day 6 dispatch when adopting
QuotaSessionacross 4 Finnhub fetchers (60/min + 800/day budget). The daily limit was not firing in production — first noticed by a manualbucket_factory.get_buckets()[0].ratesinspection during the adoption.Severity: CRITICAL for any caller passing >1 Rate; no-op for single-rate callers.
Compatibility
Limiter(List[Rate]).🤖 Generated with Claude Code