Add configurable grouping token limit - #874
Open
RamiNoodle733 wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a public configuration hook to adjust sqlparse’s DoS-prevention token cap for grouping, addressing the need to raise/disable the limit for trusted offline workloads without directly mutating internal module constants.
Changes:
- Introduces
sqlparse.engine.set_max_grouping_tokens(limit)with validation (int >= 1orNone). - Exports the setter from
sqlparse.enginefor public consumption. - Adds tests for enforcement, disabling, and invalid input handling.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
sqlparse/engine/config.py |
Adds the public setter that updates grouping.MAX_GROUPING_TOKENS with input validation. |
sqlparse/engine/__init__.py |
Re-exports set_max_grouping_tokens from the engine package namespace. |
tests/test_grouping_config.py |
Adds regression tests covering enforcement, disabling, and invalid values. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # This module is part of python-sqlparse and is released under | ||
| # the BSD License: https://opensource.org/licenses/BSD-3-Clause | ||
|
|
||
| from sqlparse.engine import grouping |
Comment on lines
+25
to
+30
| def test_set_max_grouping_tokens_can_disable_limit(restore_grouping_token_limit): | ||
| set_max_grouping_tokens(None) | ||
|
|
||
| statements = sqlparse.parse("SELECT 1") | ||
|
|
||
| assert len(statements) == 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #841
Summary
sqlparse.engine.set_max_grouping_tokens(limit)so trusted offline workloads can raise or disable the grouping token cap without mutating an internal module constant directlyNoneSafety
The default remains unchanged at 10,000 tokens. Passing
Noneis explicitly documented as appropriate only for trusted input, so the DoS protection remains enabled unless a caller intentionally changes it.Validation