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

autogenerate should resolve literal bind parameters #219

Closed
sqlalchemy-bot opened this issue Jul 28, 2014 · 7 comments
Closed

autogenerate should resolve literal bind parameters #219

sqlalchemy-bot opened this issue Jul 28, 2014 · 7 comments
Labels
autogenerate - rendering bug Something isn't working
Milestone

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Lie Ryan (@lieryan)

Suppose that you have a table like this:

my_table = Table('my_table', metadata,
  Column('status', String(8), nullable=False),
)

status_list = ('statusA', 'statusB', 'statusC')
CheckConstraint(my_table.c.status.in_(status_list),           
  name='ck_my_table_status')

alembic autogenerate currently produces a create check constraint migration that looks like this:

sa.CheckConstraint('my_table.status IN (%(status_1)s, %(status_2)s, %(status_3)s)', name='ck_my_table_status')

I would expect autogenerate to resolve the placeholders when creating the constraints and produce something like:

sa.CheckConstraint('my_table.status IN ("statusA", "statusB", "statusC")', name='ck_my_table_status')
@sqlalchemy-bot
Copy link
Author

Changes by Lie Ryan (@lieryan):

  • changed title from "Alembic produces incorrect migration" to "autogenerate should resolve literal bind parameter"

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

please try this patch

--- a/alembic/autogenerate/render.py
+++ b/alembic/autogenerate/render.py
@@ -444,7 +444,8 @@ def _render_check_constraint(constraint, autogen_context):
                             for k, v in opts)) if opts else "",
             "sqltext": str(
                 constraint.sqltext.compile(
-                    dialect=autogen_context['dialect']
+                    dialect=autogen_context['dialect'],
+                    compile_kwargs={"literal_binds": True}
                 )
             )
         }

@sqlalchemy-bot
Copy link
Author

Changes by Lie Ryan (@lieryan):

  • edited description

@sqlalchemy-bot
Copy link
Author

Lie Ryan (@lieryan) wrote:

The patch does seem to resolve the problem.

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "fasttrack"

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

0fa7716

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autogenerate - rendering bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant