Skip to content
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

the autogenerate renderer should escape the quotes in the SQL comments #529

garaud opened this issue Jan 23, 2019 · 4 comments


Copy link

garaud commented Jan 23, 2019


I use recent versions of SQLAlchemy and alembic in order to insert some comments on columns and tables (cf.

When I add a column with a comment to a table in my SQLAlchemy schema, the autogenerate feature fails to load the Python migration script due to a single quote (in my comment). I've got a syntax error since the result of the renderer is malformed.

artist = Table(
    Column("id", Integer, primary_key=True),
    Column("name", String, nullable=False, comment="artist name"),
    # added this column with a single quote in the comment
    Column("band", String, comment="Artist's band")

The _render_column in the autogenerate.render module returns something like comment='Artist's band'. There are three single quotes.

I think the renderer should escape the single quotes, e.g. here

I can replace the "'%s'" by a '"%s"' or find a proper way to escape the single quote. There might be other lines in the code where the single quote in comment should be escaped.

In my case, I write the comments in French. So I've a lot of apostrophes! 🙂

I'll submit a PR. I would like to share with you the best way to fix that.


Copy link

zzzeek commented Jan 23, 2019

Ohhhh OK right I made sure SQL quoting applied in the generated DDL but we forgot to do it in the autogen python code, OK.

Copy link

Damien Garaud has proposed a fix for this issue in the master branch:

Fix single quote escaping for the SQL comments

Copy link

zzzeek commented Jan 23, 2019


Copy link

garaud commented Jan 23, 2019

you're welcome !! 😸

Thanks for this quick review!

sqlalchemy-bot pushed a commit that referenced this issue Jan 24, 2019
Change-Id: I0c0d6701daa1c84b0905b5c4a8cab2383059389e
References: #529
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

3 participants