From: Mike Bayer Date: Sat, 28 Jan 2023 14:37:50 +0000 (-0500) Subject: Correct #7664 to include DropSchema X-Git-Tag: rel_1_4_47~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f39663404b3b4a5e3cfa6591b418435e3e54738f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Correct #7664 to include DropSchema Corrected the fix for :ticket:`7664`, released in version 2.0.0, to also include :class:`.DropSchema` which was inadvertently missed in this fix, allowing stringification without a dialect. The fixes for both constructs is backported to the 1.4 series as of 1.4.47. Fixes: #7664 Change-Id: I509b7500ee496ac1e444ea2096c2a02520167e6d (cherry picked from commit 70d1de6cff816d4627dd6b72223d9796e28aca1e) --- diff --git a/doc/build/changelog/unreleased_14/7664.rst b/doc/build/changelog/unreleased_14/7664.rst index 2188ba3bc0..466eae8bc9 100644 --- a/doc/build/changelog/unreleased_14/7664.rst +++ b/doc/build/changelog/unreleased_14/7664.rst @@ -2,6 +2,7 @@ :tags: bug, sql :tickets: 7664 - Fixed stringify for a the :class:`.CreateSchema` DDL construct, which would - fail with an ``AttributeError`` when stringified without a dialect. + Fixed stringify for a the :class:`.CreateSchema` and :class:`.DropSchema` + DDL constructs, which would fail with an ``AttributeError`` when + stringified without a dialect. diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index d47f1b2400..275d38c99f 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -440,6 +440,8 @@ class DropSchema(_CreateDropBase): __visit_name__ = "drop_schema" + stringify_dialect = "default" + def __init__(self, name, quote=None, cascade=False, **kw): """Create a new :class:`.DropSchema` construct.""" diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index be410abd33..7d8542f8c8 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -2597,6 +2597,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): @testing.combinations( (schema.CreateSchema("sa_schema"), "CREATE SCHEMA sa_schema"), + (schema.DropSchema("sa_schema"), "DROP SCHEMA sa_schema"), # note we don't yet support lower-case table() or # lower-case column() for this # ( @@ -2607,6 +2608,10 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): schema.CreateTable(Table("t", MetaData(), Column("q", Integer))), "CREATE TABLE t (q INTEGER)", ), + ( + schema.DropTable(Table("t", MetaData(), Column("q", Integer))), + "DROP TABLE t", + ), ( schema.CreateIndex( Index( @@ -2617,6 +2622,21 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): ), "CREATE INDEX foo ON t (x)", ), + ( + schema.DropIndex( + Index( + "foo", + "x", + _table=Table("t", MetaData(), Column("x", Integer)), + ) + ), + "DROP INDEX foo", + ), + ( + schema.CreateSequence(Sequence("my_seq")), + "CREATE SEQUENCE my_seq START WITH 1", + ), + (schema.DropSequence(Sequence("my_seq")), "DROP SEQUENCE my_seq"), ) def test_stringify_schema_elements(self, element, expected): eq_ignore_whitespace(str(element), expected)