diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-28 09:37:50 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-28 09:41:47 -0500 |
commit | f39663404b3b4a5e3cfa6591b418435e3e54738f (patch) | |
tree | 5f1cd4b689906cef85b3f383aef758eda70e8d38 | |
parent | 3fe348e3ca33fcb38f2942e6acdaa2222fdcdb83 (diff) | |
download | sqlalchemy-f39663404b3b4a5e3cfa6591b418435e3e54738f.tar.gz |
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)
-rw-r--r-- | doc/build/changelog/unreleased_14/7664.rst | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/ddl.py | 2 | ||||
-rw-r--r-- | test/sql/test_metadata.py | 20 |
3 files changed, 25 insertions, 2 deletions
diff --git a/doc/build/changelog/unreleased_14/7664.rst b/doc/build/changelog/unreleased_14/7664.rst index 2188ba3bc..466eae8bc 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 d47f1b240..275d38c99 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 be410abd3..7d8542f8c 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 # ( @@ -2608,6 +2609,10 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): "CREATE TABLE t (q INTEGER)", ), ( + schema.DropTable(Table("t", MetaData(), Column("q", Integer))), + "DROP TABLE t", + ), + ( schema.CreateIndex( Index( "foo", @@ -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) |