Skip to content

Commit f37fda8

Browse files
Merge pull request #33 from RudolfCardinal/execute-ddl-commit
Always commit when executing DDL
2 parents 18c6fdc + 9bbb52b commit f37fda8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cardinal_pythonlib/sqlalchemy/schema.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,18 @@ def execute_ddl(
417417
if sql:
418418
ddl = DDL(sql)
419419
with engine.connect() as connection:
420-
# DDL doesn't need a COMMIT.
421420
connection.execute(ddl)
421+
# DDL may need a commit for some dialects:
422+
#
423+
# Generic (but generic may not be useful)
424+
# https://stackoverflow.com/questions/730621/do-ddl-statements-always-give-you-an-implicit-commit-or-can-you-get-an-implicit
425+
# Oracle - autocommitted?
426+
# https://docs.oracle.com/cd/A97335_02/apps.102/a83723/keyprog6.htm
427+
# but not Postgres?
428+
# https://dba.stackexchange.com/questions/340916/why-must-i-commit-after-the-alter-table-ddl-to-make-changes-visible
429+
# and in SQL Server they are "batched" so not entirely autocommitted
430+
# https://www.mssqltips.com/sqlservertip/4591/ddl-commands-in-transactions-in-sql-server-versus-oracle/
431+
connection.commit()
422432

423433

424434
# =============================================================================

docs/source/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,3 +880,8 @@ Quick links:
880880

881881
- Allow ``db_url`` parameter to
882882
``cardinal_pythonlib.sqlalchemy.alembic_func.create_database_migration_numbered_style``.
883+
884+
**2.0.4**
885+
886+
- Fix :func:`cardinal_pythonlib.sqlalchemy.schema.execute_ddl` so that it always
887+
commits. Not all dialects commit automatically.

0 commit comments

Comments
 (0)