Skip to content

Fix #2292: Gracefully handle SQLParseError in SQL formatting#2322

Closed
okiemute04 wants to merge 2 commits intodjango-commons:mainfrom
okiemute04:fix-2292-sql-parse-error
Closed

Fix #2292: Gracefully handle SQLParseError in SQL formatting#2322
okiemute04 wants to merge 2 commits intodjango-commons:mainfrom
okiemute04:fix-2292-sql-parse-error

Conversation

@okiemute04
Copy link
Copy Markdown

Description

This PR adds graceful error handling to SQL formatting when queries contain large IN clauses (5000+ items).

When formatting SQL queries with huge IN clauses:

  • sqlparse >= 0.5.5: Raises SQLParseError → SQL panel crashes with 500 error
  • sqlparse < 0.5.5: Causes 10-18 second freeze → poor UX

The solution wraps parse_sql() calls in try/except blocks, catches SQLParseError and RecursionError, and returns a user-friendly message with the original SQL when formatting fails.

Fixes #2292

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

AI/LLM Usage

  • This PR includes code generated with the help of an AI/LLM

okiemute04 and others added 2 commits March 9, 2026 04:55
…tting

- Added try/except blocks around parse_sql calls
- Catch SQLParseError and RecursionError
- Return error message with original SQL when formatting fails
- Added tests for large IN clauses (5000 items)
- Prevents SQL panel crashes and freezes with large queries
@tim-schilling
Copy link
Copy Markdown
Member

There is a change addressing this in #2291 already.

@okiemute04
Copy link
Copy Markdown
Author

Thanks @tim-schilling for the heads up! I see that #2291 already addresses this issue. I'll close this PR. Appreciate you letting me know!

@okiemute04 okiemute04 closed this Mar 11, 2026
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.

SQL panel freezes or crashes with large IN clauses

2 participants