]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix mssql quote schema warning
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Jan 2019 16:36:54 +0000 (11:36 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Jan 2019 16:36:54 +0000 (11:36 -0500)
The deprecations review didn't include tests of identifier_preparer.quote.force
for backends, so MSSQL slipped through.  We have to fully reimplement
the deprecation warning here so that it passes tests which are now
enabled for all backends.

Change-Id: I9d07e6766e16b5a35b7f7566f1daf94b04346270

lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/testing/suite/test_ddl.py
test/sql/test_deprecations.py

index 5c446341c3b4fc4c66bef2a3ef32c70d72578b5c..4a83c085444da47565bce918edbe9d59384ca63a 100644 (file)
@@ -2019,14 +2019,24 @@ class MSIdentifierPreparer(compiler.IdentifierPreparer):
     def quote_schema(self, schema, force=None):
         """Prepare a quoted table and schema name."""
 
+        # need to re-implement the deprecation warning entirely
+        if force is not None:
+            # not using the util.deprecated_params() decorator in this
+            # case because of the additional function call overhead on this
+            # very performance-critical spot.
+            util.warn_deprecated(
+                "The IdentifierPreparer.quote_schema.force parameter is "
+                "deprecated and will be removed in a future release.  This "
+                "flag has no effect on the behavior of the "
+                "IdentifierPreparer.quote method; please refer to "
+                "quoted_name()."
+            )
+
         dbname, owner = _schema_elements(schema)
         if dbname:
-            result = "%s.%s" % (
-                self.quote(dbname, force),
-                self.quote(owner, force),
-            )
+            result = "%s.%s" % (self.quote(dbname), self.quote(owner))
         elif owner:
-            result = self.quote(owner, force)
+            result = self.quote(owner)
         else:
             result = ""
         return result
index fe6911c4060dbfc9f530b7b37d91776ac11ed91b..81a55e18ae47617111b575985b434fe6a9edb707 100644 (file)
@@ -14,12 +14,13 @@ from ... import Table
 class TableDDLTest(fixtures.TestBase):
     __backend__ = True
 
-    def _simple_fixture(self):
+    def _simple_fixture(self, schema=None):
         return Table(
             "test_table",
             self.metadata,
             Column("id", Integer, primary_key=True, autoincrement=False),
             Column("data", String(50)),
+            schema=schema,
         )
 
     def _underscore_fixture(self):
@@ -43,6 +44,13 @@ class TableDDLTest(fixtures.TestBase):
         table.create(config.db, checkfirst=False)
         self._simple_roundtrip(table)
 
+    @requirements.create_table
+    @util.provide_metadata
+    def test_create_table_schema(self):
+        table = self._simple_fixture(schema=config.test_schema)
+        table.create(config.db, checkfirst=False)
+        self._simple_roundtrip(table)
+
     @requirements.drop_table
     @util.provide_metadata
     def test_drop_table(self):
index 2e4042a1b264c650af291b0ba3f9de0e8726e0e5..7990cd56c69ab2301901bee4f5651fe26fa33233 100644 (file)
@@ -28,6 +28,8 @@ from sqlalchemy.testing import mock
 
 
 class DeprecationWarningsTest(fixtures.TestBase):
+    __backend__ = True
+
     def test_ident_preparer_force(self):
         preparer = testing.db.dialect.identifier_preparer
         preparer.quote("hi")