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

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Jul 28, 2014

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

This comment has been minimized.

sqlalchemy-bot commented Jul 28, 2014

Changes by Lie Ryan (@lieryan):

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

This comment has been minimized.

sqlalchemy-bot commented Jul 28, 2014

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

This comment has been minimized.

sqlalchemy-bot commented Aug 5, 2014

Changes by Lie Ryan (@lieryan):

  • edited description
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Aug 5, 2014

Lie Ryan (@lieryan) wrote:

The patch does seem to resolve the problem.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 28, 2014

Changes by Michael Bayer (@zzzeek):

  • set milestone to "fasttrack"
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 2, 2014

Michael Bayer (@zzzeek) wrote:

  • Bound parameters are now resolved as "literal" values within the
    SQL expression inside of a CheckConstraint(), when rendering the SQL
    as a text string; supported for SQLAlchemy 0.8.0 and forward.
    fixes #219

0fa7716

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 2, 2014

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