<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
Rendering ExecuteSQLOp did not respect the `alembic_module_prefix` setting due
to having `op.` hard-coded in its template.
This change updates the render logic to use the same
`_alembic_autogenerate_prefix()` as it seems the rest of the ops use.
### Checklist
This pull request is:
- [ ] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [x] A short code fix
- please include the issue number, and create an issue if none exists, which
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests. one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
- please include the issue number, and create an issue if none exists, which must
include a complete example of how the feature would look.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.
Fixes #1656
Closes: #1657
Pull-request: https://github.com/sqlalchemy/alembic/pull/1657
Pull-request-sha:
c67f4b7ce25c363d525cd2483370b0be024160d9
Change-Id: I6ca36642ed3755a2d96824498502ada6ae16f714
"Autogenerate rendering of SQL Expression language constructs "
"not supported here; please use a plain SQL string"
)
- return "op.execute(%r)" % op.sqltext
+ return "{prefix}execute({sqltext!r})".format(
+ prefix=_alembic_autogenerate_prefix(autogen_context),
+ sqltext=op.sqltext,
+ )
renderers = default_renderers.branch()
--- /dev/null
+.. change::
+ :tags: bug, operations
+ :tickets: 1656
+
+ The ExecuteSQLOp now takes into account the value configured
+ in :paramref:`configure.alembic_module_prefix` instead of always
+ defaulting to ``op.``.
+ Pull request curtesy of Avery Fischer.
op_obj,
)
+ @testing.combinations(
+ ("test.",),
+ (None,),
+ argnames="alembic_module_prefix",
+ )
+ def test_render_executesql_alembic_module_prefix(
+ self,
+ alembic_module_prefix,
+ ):
+ self.autogen_context.opts.update(
+ alembic_module_prefix=alembic_module_prefix
+ )
+ op_obj = ops.ExecuteSQLOp("drop table foo")
+ eq_(
+ autogenerate.render_op_text(self.autogen_context, op_obj),
+ f"{alembic_module_prefix or ''}execute('drop table foo')",
+ )
+
def test_render_alter_column_modify_comment(self):
op_obj = ops.AlterColumnOp(
"sometable", "somecolumn", modify_comment="This is a comment"