aminghadersohi commented on PR #37200:
URL: https://github.com/apache/superset/pull/37200#issuecomment-3761695308
## Additional CodeAnt Suggestions Addressed
Pushed commit `03e88de11b` with the following changes:
### 1. OOM Protection (middleware.py) ✅
- Now uses `except Exception` with `# noqa: BLE001` for token estimation
fallback
- Catches MemoryError specifically first, then any other exception
- This is the correct pattern for defensive OOM protection
### 2. Conservative Fallback (token_utils.py:119) ✅
- `get_response_size_bytes()` now returns `1_000_000` (1MB) on failure
instead of `0`
- This prevents oversized responses from bypassing size checks
- Previously returning 0 would underestimate and allow large responses
through
### 3. Consistent Exception Handling ✅
- All serialization-related exception handlers now use `except Exception`
with noqa
- Added to: `estimate_response_tokens()`, `get_response_size_bytes()`,
`_identify_large_fields()`
### Note on Test File Context Manager Syntax (lines 72, 98, 146)
The parenthesized context manager syntax used in the test file:
```python
with (
patch("..."),
patch("..."),
):
```
is **valid Python 3.10+ syntax** (PEP 617). Superset requires Python 3.10+
(`requires-python = ">=3.10"` in pyproject.toml), and `ruff` formatter actively
prefers this style. The CodeAnt warnings about this being a "tuple bug" are
false positives for Python 3.10+ projects.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]