Skip to content

CHORE: escape single quotes in inspectdb --schema argument - #583

Open
Gaurav Sharma (bewithgaurav) wants to merge 1 commit into
devfrom
bewithgaurav/quote-inspectdb-schema-arg
Open

CHORE: escape single quotes in inspectdb --schema argument#583
Gaurav Sharma (bewithgaurav) wants to merge 1 commit into
devfrom
bewithgaurav/quote-inspectdb-schema-arg

Conversation

@bewithgaurav

Copy link
Copy Markdown
Collaborator

Summary

inspectdb --schema <name> wraps the provided value as a T-SQL string literal in settings.SCHEMA_TO_INSPECT. A single quote in the value (e.g. a schema named O'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.

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>
@bewithgaurav
Gaurav Sharma (bewithgaurav) marked this pull request as ready for review August 25, 2026 05:48
Copilot AI lite review requested due to automatic review settings August 25, 2026 05:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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