CHORE: escape single quotes in inspectdb --schema argument - #583
Open
Gaurav Sharma (bewithgaurav) wants to merge 1 commit into
Open
CHORE: escape single quotes in inspectdb --schema argument#583Gaurav Sharma (bewithgaurav) wants to merge 1 commit into
Gaurav Sharma (bewithgaurav) wants to merge 1 commit into
Conversation
The --schema value is wrapped as a T-SQL string literal in settings.SCHEMA_TO_INSPECT. An embedded single quote (e.g. a schema named O'Brien) ended the literal early, so the resulting name no longer matched the intended schema. Double any embedded single quotes so the name is preserved verbatim. Adds a testapp regression test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Gaurav Sharma (bewithgaurav)
marked this pull request as ready for review
August 25, 2026 05:48
Copilot started reviewing on behalf of
Gaurav Sharma (bewithgaurav)
August 25, 2026 05:49
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Updates inspectdb --schema to preserve schema names containing apostrophes in T-SQL literals.
Changes:
- Escapes embedded single quotes by doubling them.
- Adds DB-free regression tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
testapp/tests/test_inspectdb.py |
Tests schema literal generation. |
mssql/management/commands/inspectdb.py |
Escapes schema names safely. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
inspectdb --schema <name>wraps the provided value as a T-SQL string literal insettings.SCHEMA_TO_INSPECT. A single quote in the value (e.g. a schema namedO'Brien) ended the literal early, so the resulting name no longer matched the intended schema. This doubles any embedded single quotes so the schema name is preserved verbatim.Changes
mssql/management/commands/inspectdb.py: double embedded single quotes when building the schema literal.testapp/tests/test_inspectdb.py: regression test — an apostrophe-containing schema stays a literal name; a plain schema is unchanged.The regression test patches the parent
handle, so it is DB-free and runs without a live SQL Server.