diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-24 15:34:27 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-24 15:35:43 -0500 |
commit | 2c3372f6c03c7d15325cad08c9fd6d08c68fa2fd (patch) | |
tree | 5b3d982aa0d52ef74abe5f0cbf6accfce4044610 | |
parent | 102114accc5a7caf76629c4c2ab108ddbfcbe81a (diff) | |
download | sqlalchemy-2c3372f6c03c7d15325cad08c9fd6d08c68fa2fd.tar.gz |
fix stringify for CreateSchema
Fixed stringify for a the :class:`.CreateSchema` DDL construct, which would
fail with an ``AttributeError`` when stringified without a dialect.
Fixes: #7664
Change-Id: Ifc1769604bc5219c060f5112f7bdea0f780f1a1c
(cherry picked from commit 90f4b5d84f248d95f3df38e74be92b23fd880e42)
-rw-r--r-- | doc/build/changelog/unreleased_14/7664.rst | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/ddl.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/assertions.py | 2 | ||||
-rw-r--r-- | test/sql/test_metadata.py | 27 |
4 files changed, 38 insertions, 0 deletions
diff --git a/doc/build/changelog/unreleased_14/7664.rst b/doc/build/changelog/unreleased_14/7664.rst new file mode 100644 index 000000000..2188ba3bc --- /dev/null +++ b/doc/build/changelog/unreleased_14/7664.rst @@ -0,0 +1,7 @@ +.. 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. + diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index bed64a567..d47f1b240 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -422,6 +422,8 @@ class CreateSchema(_CreateDropBase): __visit_name__ = "create_schema" + stringify_dialect = "default" + def __init__(self, name, quote=None, **kw): """Create a new :class:`.CreateSchema` construct.""" diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index 5c646790b..754f535f5 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -334,8 +334,10 @@ def startswith_(a, fragment, msg=None): def eq_ignore_whitespace(a, b, msg=None): a = re.sub(r"^\s+?|\n", "", a) a = re.sub(r" {2,}", " ", a) + a = re.sub(r"\t", "", a) b = re.sub(r"^\s+?|\n", "", b) b = re.sub(r" {2,}", " ", b) + b = re.sub(r"\t", "", b) assert a == b, msg or "%r != %r" % (a, b) diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 50cf25337..be410abd3 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -48,6 +48,7 @@ from sqlalchemy.testing import AssertsCompiledSQL from sqlalchemy.testing import ComparesTables from sqlalchemy.testing import emits_warning from sqlalchemy.testing import eq_ +from sqlalchemy.testing import eq_ignore_whitespace from sqlalchemy.testing import expect_raises_message from sqlalchemy.testing import fixtures from sqlalchemy.testing import is_ @@ -2594,6 +2595,32 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): t2 = Table("t2", m, Column("x", Integer, ForeignKey("bar.t1.x"))) assert t2.c.x.references(t1.c.x) + @testing.combinations( + (schema.CreateSchema("sa_schema"), "CREATE SCHEMA sa_schema"), + # note we don't yet support lower-case table() or + # lower-case column() for this + # ( + # schema.CreateTable(table("t", column("q", Integer))), + # "CREATE TABLE t (q INTEGER)", + # ), + ( + schema.CreateTable(Table("t", MetaData(), Column("q", Integer))), + "CREATE TABLE t (q INTEGER)", + ), + ( + schema.CreateIndex( + Index( + "foo", + "x", + _table=Table("t", MetaData(), Column("x", Integer)), + ) + ), + "CREATE INDEX foo ON t (x)", + ), + ) + def test_stringify_schema_elements(self, element, expected): + eq_ignore_whitespace(str(element), expected) + def test_create_drop_schema(self): self.assert_compile( |