]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Correct #7664 to include DropSchema
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 28 Jan 2023 14:37:50 +0000 (09:37 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 28 Jan 2023 14:41:47 +0000 (09:41 -0500)
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)

doc/build/changelog/unreleased_14/7664.rst
lib/sqlalchemy/sql/ddl.py
test/sql/test_metadata.py

index 2188ba3bc0ff45794f74b1f9a11dca5c6f150224..466eae8bc95ac2c50711de1e34a92813631ffcc3 100644 (file)
@@ -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.
 
index d47f1b2400733880b72ba1ec41fab75dcd1b9f06..275d38c99fe9ef92cc0a68782bcdb52ca56cf455 100644 (file)
@@ -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."""
 
index be410abd33a6b38b3e5d18352eb198b0c6df6239..7d8542f8c8ef4e72fcaf2f2dcaee095fab3cf9be 100644 (file)
@@ -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)