]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
remove erroneous None check from _assert_str
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 4 Sep 2021 15:29:10 +0000 (11:29 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 4 Sep 2021 15:29:10 +0000 (11:29 -0400)
Fixed issue in ``URL`` where validation of "drivername" would not
appropriately respond to the ``None`` value where a string were expected.

Fixes: #6983
Change-Id: If546c373a60533779595a9e393ea9a59a9b8a96f

doc/build/changelog/unreleased_14/6983.rst [new file with mode: 0644]
lib/sqlalchemy/engine/url.py
test/engine/test_parseconnect.py

diff --git a/doc/build/changelog/unreleased_14/6983.rst b/doc/build/changelog/unreleased_14/6983.rst
new file mode 100644 (file)
index 0000000..2aa31e8
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, engine
+    :tickets: 6983
+
+    Fixed issue in ``URL`` where validation of "drivername" would not
+    appropriately respond to the ``None`` value where a string were expected.
index b924f1c7303e2bee9ffc8c1fa47d092abad91f5b..1b96c3c2e1790c100c64b9f6091b5b4436b55eee 100644 (file)
@@ -154,9 +154,6 @@ class URL(
 
     @classmethod
     def _assert_str(cls, v, paramname):
-        if v is None:
-            return v
-
         if not isinstance(v, compat.string_types):
             raise TypeError("%s must be a string" % paramname)
         return v
index ea949dfd6451344c54f545e260cce46b29b00d63..9acedaa8526e3081ac7d54409bd4ac8af59ab211 100644 (file)
@@ -16,6 +16,7 @@ from sqlalchemy.testing import is_
 from sqlalchemy.testing import is_false
 from sqlalchemy.testing import is_true
 from sqlalchemy.testing import mock
+from sqlalchemy.testing.assertions import expect_deprecated
 from sqlalchemy.testing.mock import call
 from sqlalchemy.testing.mock import MagicMock
 from sqlalchemy.testing.mock import Mock
@@ -275,20 +276,35 @@ class URLTest(fixtures.TestBase):
             url.make_url("drivername:///?%s" % expected),
         )
 
-    @testing.combinations(
-        "username",
-        "host",
-        "database",
-    )
-    def test_only_str_constructor(self, argname):
+    @testing.combinations("username", "host", "database", argnames="argname")
+    @testing.combinations((35.8), (True,), argnames="value")
+    def test_only_str_constructor(self, argname, value):
         assert_raises_message(
             TypeError,
             "%s must be a string" % argname,
             url.URL.create,
             "somedriver",
-            **{argname: 35.8}
+            **{argname: value}
         )
 
+    @testing.combinations("username", "host", "database", argnames="argname")
+    def test_none_ok(self, argname):
+        u1 = url.URL.create("drivername", **{argname: None})
+        is_(getattr(u1, argname), None)
+
+    @testing.combinations((35.8), (True,), (None,), argnames="value")
+    def test_only_str_drivername_no_none(self, value):
+        assert_raises_message(
+            TypeError, "drivername must be a string", url.URL.create, value
+        )
+
+    @testing.combinations((35.8), (True,), (None,), argnames="value")
+    def test_only_str_drivername_no_none_legacy(self, value):
+        with expect_deprecated(r"Calling URL\(\) directly"):
+            assert_raises_message(
+                TypeError, "drivername must be a string", url.URL, value
+            )
+
     @testing.combinations(
         "username",
         "host",