]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Don't emit pyodbc "no driver" warning for empty URL
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 May 2020 17:14:58 +0000 (13:14 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 May 2020 17:15:30 +0000 (13:15 -0400)
Fixed an issue in the pyodbc connector such that a warning about pyodbc
"drivername" would be emitted when using a totally empty URL.  Empty URLs
are normal when producing a non-connected dialect object or when using the
"creator" argument to create_engine(). The warning now only emits if the
driver name is missing but other parameters are still present.

Fixes: #5346
Change-Id: I0ee6f5fd5af7faca63bf0d7034410942f40834a8

doc/build/changelog/unreleased_13/5346.rst [new file with mode: 0644]
lib/sqlalchemy/connectors/pyodbc.py
test/dialect/mssql/test_engine.py

diff --git a/doc/build/changelog/unreleased_13/5346.rst b/doc/build/changelog/unreleased_13/5346.rst
new file mode 100644 (file)
index 0000000..7b4e0fb
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, mssql, pyodbc
+    :tickets: 5346
+
+    Fixed an issue in the pyodbc connector such that a warning about pyodbc
+    "drivername" would be emitted when using a totally empty URL.  Empty URLs
+    are normal when producing a non-connected dialect object or when using the
+    "creator" argument to create_engine(). The warning now only emits if the
+    driver name is missing but other parameters are still present.
index cd79a3ada02c7e874d5a7b83b4aad2c106be5ff4..df1b2afdbb18502f6e75abd8cb12bcc93e11aa57 100644 (file)
@@ -75,7 +75,8 @@ class PyODBCConnector(Connector):
 
                 connectors = []
                 driver = keys.pop("driver", self.pyodbc_driver_name)
-                if driver is None:
+                if driver is None and keys:
+                    # note if keys is empty, this is a totally blank URL
                     util.warn(
                         "No driver name specified; "
                         "this is expected by PyODBC when using "
index 00babf8ce7ebec51a078511451d32a8f06eaf1ab..0dea2688a7901334c61a6a561e7f66788ddf6a44 100644 (file)
@@ -66,6 +66,13 @@ class ParseConnectTest(fixtures.TestBase):
             connection,
         )
 
+    def test_pyodbc_empty_url_no_warning(self):
+        dialect = pyodbc.dialect()
+        u = url.make_url("mssql+pyodbc://")
+
+        # no warning is emitted
+        dialect.create_connect_args(u)
+
     def test_pyodbc_host_no_driver(self):
         dialect = pyodbc.dialect()
         u = url.make_url("mssql://username:password@hostspec/database")