Skip to content

Escape revision messages before embedding in script.py.mako docstrings - #1881

Closed
Eryx-Z wants to merge 1 commit into
sqlalchemy:mainfrom
Eryx-Z:fix/1879-escape-revision-message-docstring
Closed

Eryx-Z wants to merge 1 commit into
sqlalchemy:mainfrom
Eryx-Z:fix/1879-escape-revision-message-docstring

Conversation

@Eryx-Z

@Eryx-Z Eryx-Z commented Oct 17, 2026

Copy link
Copy Markdown

Summary

Revision -m messages are rendered into a triple-quoted docstring by every built-in script.py.mako. Unescaped """ terminated that docstring (remaining text ran as module code on import), and backslashes were interpreted as Python escapes so script.doc did not round-trip.

Escape the message in generate_revision() before template render.

Fixes #1879.

Test plan

  • New tests: triple-quote and backslash messages round-trip through script.doc
  • Existing RevisionCommandTest.test_create_script_basic still passes

Unescaped triple quotes in -m messages terminated the generated module
docstring and allowed the remainder to execute on import. Backslashes
were also interpreted as Python escapes, so script.doc did not
round-trip. Escape both before template render.

Fixes sqlalchemy#1879.
@sqla-tester

Copy link
Copy Markdown
Collaborator

Hi, and thanks for the pull request!

This project accepts pull requests only for issues that a maintainer has already marked with the open for pull requests label. That way we can settle on an approach before anyone spends time writing code.

This pull request references issue #1879, which hasn't been marked open for pull requests, so the change isn't authorized yet and I'm closing it automatically. Once a maintainer adds the label to #1879, reopen this pull request and it will stay open. If #1879 needs more detail before that can happen, a complete runnable example is usually the missing piece, and adding one to the issue is the fastest way to get there.

This is automatic and procedural. It isn't a judgment on your change, and nothing you've written here is lost.

Thanks for your interest in the project!

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.

Revision message is rendered unescaped into the migration docstring; triple quotes and backslashes break the generated script

2 participants