Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions snuba/web/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*CLICKHOUSE_TYPING_ERROR_CODES,
# queries that can never return the amount of data requested by the user are not an internal error
ErrorCodes.MEMORY_LIMIT_EXCEEDED,
# query exceeded the max_bytes_to_read limit set by an allocation policy
ErrorCodes.TOO_MANY_BYTES,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOO_MANY_BYTES missing from non-retryable error codes set

Medium Severity

TOO_MANY_BYTES is added to ACCEPTABLE_CLICKHOUSE_ERROR_CODES but not to NON_RETRYABLE_CLICKHOUSE_ERROR_CODES. Previously this error was converted to RateLimitExceeded, so it never hit the non-retryable check. Now it flows through as a ClickhouseError, so in the subscription executor consumer it triggers a SubscriptionQueryException (retry), even though the error is deterministic and retrying won't help since the max_bytes_to_read limit is fixed by allocation policy.

Fix in Cursor Fix in Web

}

NON_RETRYABLE_CLICKHOUSE_ERROR_CODES = {
Expand Down
6 changes: 0 additions & 6 deletions snuba/web/db_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,6 @@ def _raw_query(
elif isinstance(cause, ClickhouseError):
error_code = cause.code
status = get_query_status_from_error_codes(error_code)
if error_code == ErrorCodes.TOO_MANY_BYTES:
calculated_cause = RateLimitExceeded(
"Query scanned more than the allocated amount of bytes",
quota_allowance=stats["quota_allowance"],
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculated_cause variable is now redundant dead code

Low Severity

The calculated_cause variable is assigned to cause on line 472 and is never reassigned in any branch. It was previously needed because the TOO_MANY_BYTES branch would reassign it to a RateLimitExceeded instance. With that branch removed, calculated_cause is always identical to cause, making it dead code. The from calculated_cause on line 509 can simply use from cause directly.

Fix in Cursor Fix in Web

with configure_scope() as scope:
fingerprint = ["{{default}}", str(cause.code), dataset_name]
if error_code not in constants.CLICKHOUSE_SYSTEMATIC_FAILURES:
Expand Down
11 changes: 4 additions & 7 deletions tests/test_snql_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,12 +1329,9 @@ def test_allocation_policy_max_bytes_to_read(self) -> None:
}
),
)
assert response.status_code == 429

assert (
response.json["error"]["message"]
== "Query scanned more than the allocated amount of bytes"
)
assert response.status_code == 400
assert response.json["error"]["type"] == "clickhouse"
assert response.json["error"]["code"] == 307

expected_quota_allowance = {
"details": {
Expand Down Expand Up @@ -1373,7 +1370,7 @@ def test_allocation_policy_max_bytes_to_read(self) -> None:
},
}

assert response.json["quota_allowance"] == expected_quota_allowance
assert response.json["stats"]["quota_allowance"] == expected_quota_allowance

def test_allocation_policy_violation(self) -> None:
with patch(
Expand Down
Loading