10000 Fixed #36420 -- Used actual SQLite limits in last_executed_query() quoting. by myoungjinGo-BE · Pull Request #19517 · django/django · GitHub
[go: up one dir, main page]

Skip to content

Fixed #36420 -- Used actual SQLite limits in last_executed_query() quoting. #19517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into 8000
base: main
Choose a base branch
from

Conversation

myoungjinGo-BE
Copy link
Contributor

Trac ticket number

ticket-36420

Branch description

Replaced the hardcoded batch size in last_executed_query() for SQLite with a dynamic limit based on sqlite3.Connection.getlimit() (Python 3.11+). This ensures that parameter quoting does not exceed SQLite’s runtime constraints, avoiding OperationalError on systems with custom-compiled SQLite (e.g., with increased SQLITE_MAX_VARIABLE_NUMBER).

This change is safe because Django 6.0 and later versions have dropped support for Python 3.10 and 3.11 (#36005), and thus getlimit() (introduced in Python 3.11) is always available.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

BATCH_SIZE = 999
if len(params) > BATCH_SIZE:
connection = self.connection.connection
variable_limit = connection.getlimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now available as self.connection.features.max_query_params as of #19427.

@property
def max_query_params(self):
"""
SQLite has a variable limit per query. The limit can be changed using
the SQLITE_MAX_VARIABLE_NUMBER compile-time option (which defaults to
999 in versions < 3.32.0 or 32766 in newer versions) or lowered per
connection at run-time with setlimit(SQLITE_LIMIT_VARIABLE_NUMBER, N).
"""
return self.connection.connection.getlimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER)

Suggested change
variable_limit = connection.getlimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER)
variable_limit = self.connection.features.max_query_params

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.

2 participants
0