Skip to content

Expose configurable grouping token limit - #899

Open
RamiNoodle733 wants to merge 5 commits into
andialbrecht:masterfrom
RamiNoodle733:fix-configurable-grouping-token-limit-841
Open

RamiNoodle733 wants to merge 5 commits into
andialbrecht:masterfrom
RamiNoodle733:fix-configurable-grouping-token-limit-841

Conversation

@RamiNoodle733

@RamiNoodle733 RamiNoodle733 commented Sep 14, 2026

Copy link
Copy Markdown

Fixes #841.

Adds a public sqlparse.set_max_grouping_tokens() API so applications can raise, lower, or disable the grouping-stage token cap without importing and mutating an internal module global directly.

The setter accepts a positive integer or None, rejects invalid values such as booleans, non-integers, zero, and negatives, and applies process-wide to subsequent parsing and formatting operations. The docstring explicitly warns that disabling or increasing the guard is not recommended for untrusted SQL.

Targeted regression coverage verifies that lowering the limit changes parser behavior, None disables the token-count guard, invalid values are rejected, the original global limit is restored after each test, and the same configured guard is enforced through sqlparse.format().

Duplicate consolidation: #892 was an accidental overlapping implementation for the same #841 root cause and has been closed in favor of this canonical PR. Earlier #874 was already closed.

Validation: branch diff is limited to the public setter/export, its safety documentation, and focused tests. The full pytest suite was not run locally because this automation environment does not have a runnable repository checkout, so no local test-suite result is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make MAX_GROUPING_TOKENS can be set outside of grouping.py

1 participant