Skip to content

Commit e0c6985

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 1f0e880 commit e0c6985

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
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:

0 commit comments

Comments
 (0)