Skip to content

Commit c66b632

Browse files
cvxluoclaude
andcommitted
feat(api): return TOO_MANY_BYTES as clickhouse error instead of rate limit
Stop converting ClickHouse TOO_MANY_BYTES (code 307) errors into RateLimitExceeded. This lets consumers (e.g. sentry) distinguish "query scanned too many bytes" from snuba-level rate limiting. - Remove RateLimitExceeded conversion for TOO_MANY_BYTES in db_query.py - Add TOO_MANY_BYTES to ACCEPTABLE_CLICKHOUSE_ERROR_CODES (returns 400) - Update test to assert clickhouse error type with code 307 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 795ac47 commit c66b632

File tree

3 files changed

+2
-11
lines changed

3 files changed

+2
-11
lines changed

snuba/web/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*CLICKHOUSE_TYPING_ERROR_CODES,
1717
# queries that can never return the amount of data requested by the user are not an internal error
1818
ErrorCodes.MEMORY_LIMIT_EXCEEDED,
19+
# query exceeded the max_bytes_to_read limit set by an allocation policy
20+
ErrorCodes.TOO_MANY_BYTES,
1921
}
2022

2123
NON_RETRYABLE_CLICKHOUSE_ERROR_CODES = {

snuba/web/db_query.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,6 @@ def _raw_query(
476476
elif isinstance(cause, ClickhouseError):
477477
error_code = cause.code
478478
status = get_query_status_from_error_codes(error_code)
479-
if error_code == ErrorCodes.TOO_MANY_BYTES:
480-
calculated_cause = RateLimitExceeded(
481-
"Query scanned more than the allocated amount of bytes",
482-
quota_allowance=stats["quota_allowance"],
483-
)
484-
485479
with configure_scope() as scope:
486480
fingerprint = ["{{default}}", str(cause.code), dataset_name]
487481
if error_code not in constants.CLICKHOUSE_SYSTEMATIC_FAILURES:

tests/test_snql_api.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,15 +1329,10 @@ def test_allocation_policy_max_bytes_to_read(self) -> None:
13291329
}
13301330
),
13311331
)
1332-
# TOO_MANY_BYTES is a clickhouse error, not a rate limit.
1333-
# The response should surface the clickhouse error type and code
1334-
# so that consumers (e.g. sentry) can distinguish it from
1335-
# snuba-level rate limiting.
13361332
assert response.status_code == 400
13371333
assert response.json["error"]["type"] == "clickhouse"
13381334
assert response.json["error"]["code"] == 307
13391335

1340-
# quota_allowance should still be available in stats
13411336
expected_quota_allowance = {
13421337
"details": {
13431338
"MaxBytesPolicy123": {

0 commit comments

Comments
 (0)