Summary
Fixed the DoS protection implementation introduced in commit 40ed3aa to raise SQLParseError exceptions instead of silently returning None when grouping limits are exceeded.
Problem
In commit 40ed3aa, DoS protection was added with MAX_GROUPING_DEPTH and MAX_GROUPING_TOKENS limits. However, when these limits were triggered, the functions simply returned None, causing parsing to silently fail without any indication of what went wrong.
Solution
Modified _group_matching() and _group() functions in sqlparse/engine/grouping.py to raise SQLParseError with clear error messages:
- "Maximum grouping depth exceeded ({limit})."
- "Maximum number of tokens exceeded ({limit})."
Changes
- Added import of
SQLParseError in sqlparse/engine/grouping.py
- Updated
_group_matching() to raise exceptions instead of returning None
- Updated
_group() to raise exceptions instead of returning None
- Updated tests in
tests/test_dos_prevention.py to expect SQLParseError
Testing
All 482 tests pass, including the 5 DoS prevention tests that now correctly expect SQLParseError to be raised.
Summary
Fixed the DoS protection implementation introduced in commit 40ed3aa to raise
SQLParseErrorexceptions instead of silently returningNonewhen grouping limits are exceeded.Problem
In commit 40ed3aa, DoS protection was added with
MAX_GROUPING_DEPTHandMAX_GROUPING_TOKENSlimits. However, when these limits were triggered, the functions simply returnedNone, causing parsing to silently fail without any indication of what went wrong.Solution
Modified
_group_matching()and_group()functions insqlparse/engine/grouping.pyto raiseSQLParseErrorwith clear error messages:Changes
SQLParseErrorinsqlparse/engine/grouping.py_group_matching()to raise exceptions instead of returningNone_group()to raise exceptions instead of returningNonetests/test_dos_prevention.pyto expectSQLParseErrorTesting
All 482 tests pass, including the 5 DoS prevention tests that now correctly expect
SQLParseErrorto be raised.