From: Mike Bayer Date: Sat, 28 Jan 2023 14:37:50 +0000 (-0500) Subject: Correct #7664 to include DropSchema X-Git-Tag: rel_2_0_1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70d1de6cff816d4627dd6b72223d9796e28aca1e;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 --- diff --git a/doc/build/changelog/changelog_20.rst b/doc/build/changelog/changelog_20.rst index 8f604dbca6..a91a137981 100644 --- a/doc/build/changelog/changelog_20.rst +++ b/doc/build/changelog/changelog_20.rst @@ -16,6 +16,16 @@ :version: 2.0.0 :released: January 26, 2023 + .. change:: + :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. Update: Note this fix failed to accommodate for + :class:`.DropSchema`; a followup fix in version 2.0.1 repairs this + case. The fix for both elements is backported to 1.4.47. + .. change:: :tags: usecase, orm extensions :tickets: 5145 diff --git a/doc/build/changelog/unreleased_14/7664.rst b/doc/build/changelog/unreleased_14/7664.rst index 5e4ae56890..466eae8bc9 100644 --- a/doc/build/changelog/unreleased_14/7664.rst +++ b/doc/build/changelog/unreleased_14/7664.rst @@ -1,8 +1,8 @@ .. change:: :tags: bug, sql :tickets: 7664 - :versions: 2.0.0 - 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/doc/build/changelog/unreleased_20/7664_update.rst b/doc/build/changelog/unreleased_20/7664_update.rst new file mode 100644 index 0000000000..8f6199e9e4 --- /dev/null +++ b/doc/build/changelog/unreleased_20/7664_update.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, sql + :tickets: 7664 + + 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. + diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index 715e364272..826ff687e1 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -497,6 +497,8 @@ class DropSchema(_DropBase): __visit_name__ = "drop_schema" + stringify_dialect = "default" # type: ignore + def __init__( self, name, diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 0cd73922e9..684ad3a075 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -2623,6 +2623,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 # ( @@ -2633,6 +2634,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( @@ -2643,6 +2648,18 @@ 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"), + (schema.DropSequence(Sequence("my_seq")), "DROP SEQUENCE my_seq"), ) def test_stringify_schema_elements(self, element, expected): eq_ignore_whitespace(str(element), expected)