Skip to content

Commit

Permalink
Remove typo in _exec_drop_col_fk_constraint
Browse files Browse the repository at this point in the history
Fixed issue where the ``mssql_drop_foreign_key=True`` flag on
``op.drop_column`` would lead to incorrect syntax error due to a typo in the
SQL emitted, same typo was present in the test as well so it was not
detected. Pull request courtesy Oleg Shigorin.

Fixes: #716
Closes: #717
Pull-request: #717
Pull-request-sha: dcd90fb

Change-Id: I022a66a3bcebf689945cfbd36bed0ebed248364f
  • Loading branch information
Nuqlear authored and zzzeek committed Jul 25, 2020
1 parent 8cf1fd2 commit c9ba30a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion alembic/ddl/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _exec_drop_col_fk_constraint(element, compiler, **kw):
sys.foreign_keys fk join sys.foreign_key_columns fkc
on fk.object_id=fkc.constraint_object_id
where fkc.parent_object_id = object_id('%(schema_dot)s%(tname)s')
`and col_name(fkc.parent_object_id, fkc.parent_column_id) = '%(colname)s'
and col_name(fkc.parent_object_id, fkc.parent_column_id) = '%(colname)s'
exec('alter table %(tname_quoted)s drop constraint ' + @const_name)""" % {
"tname": tname,
"colname": colname,
Expand Down
8 changes: 8 additions & 0 deletions docs/build/unreleased/716.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. change::
:tags: bug, mssql
:tickets: 716

Fixed issue where the ``mssql_drop_foreign_key=True`` flag on
``op.drop_column`` would lead to incorrect syntax error due to a typo in the
SQL emitted, same typo was present in the test as well so it was not
detected. Pull request courtesy Oleg Shigorin.
4 changes: 2 additions & 2 deletions tests/test_mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_drop_column_w_fk(self):
"select @const_name = [name] from\n"
"sys.foreign_keys fk join sys.foreign_key_columns fkcon "
"fk.object_id=fkc.constraint_object_id\n"
"where fkc.parent_object_id = object_id('t1')`and "
"where fkc.parent_object_id = object_id('t1')\nand "
"col_name(fkc.parent_object_id, fkc.parent_column_id) = 'c1'\n"
"exec('alter table t1 drop constraint ' + @const_name)"
)
Expand All @@ -208,7 +208,7 @@ def test_drop_column_w_fk_schema(self):
"select @const_name = [name] from\n"
"sys.foreign_keys fk join sys.foreign_key_columns fkcon "
"fk.object_id=fkc.constraint_object_id\n"
"where fkc.parent_object_id = object_id('xyz.t1')`and "
"where fkc.parent_object_id = object_id('xyz.t1')\nand "
"col_name(fkc.parent_object_id, fkc.parent_column_id) = 'c1'\n"
"exec('alter table xyz.t1 drop constraint ' + @const_name)"
)
Expand Down

0 comments on commit c9ba30a

Please sign in to comment.