]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
check for string_types, not str, for py2 support
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Dec 2021 16:23:07 +0000 (11:23 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Dec 2021 16:26:23 +0000 (11:26 -0500)
Fixed regression in the :func:`_engine.make_url` function used to parse URL
strings where the query string parsing would go into a recursion overflow
if a Python 2 ``u''`` string were used.

Fixes: #7446
Change-Id: I081275673e6240a52f71da7dfaaf04e6fe32cf48

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

diff --git a/doc/build/changelog/unreleased_14/7446.rst b/doc/build/changelog/unreleased_14/7446.rst
new file mode 100644 (file)
index 0000000..d92eb13
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, engine, regression
+    :tickets: 7446
+
+    Fixed regression in the :func:`_engine.make_url` function used to parse URL
+    strings where the query string parsing would go into a recursion overflow
+    if a Python 2 ``u''`` string were used.
index 320e69fbc383d19898c81d55f99bbbb9a2551226..a73b81a319b338b0a9ec6c5e538f9be68f530f7a 100644 (file)
@@ -182,7 +182,7 @@ class URL(
             return util.EMPTY_DICT
 
         def _assert_value(val):
-            if isinstance(val, str):
+            if isinstance(val, compat.string_types):
                 return val
             elif isinstance(val, collections_abc.Sequence):
                 return tuple(_assert_value(elem) for elem in val)
index f553b1dab569fc79100c5c9f554e4f83a1d99173..28362ba2a1c8f400ffba43e8b247ad2148cff597 100644 (file)
@@ -6,6 +6,7 @@ from sqlalchemy import engine_from_config
 from sqlalchemy import exc
 from sqlalchemy import pool
 from sqlalchemy import testing
+from sqlalchemy import util
 from sqlalchemy.dialects import plugins
 from sqlalchemy.dialects import registry
 from sqlalchemy.engine.default import DefaultDialect
@@ -181,6 +182,17 @@ class URLTest(fixtures.TestBase):
         eq_(u.query, {"arg1=": "param1", "arg2": "param 2"})
         eq_(str(u), test_url)
 
+    def test_query_string_py2_unicode(self):
+        url_str = u"dialect://user:pass@host/?arg1=param1&arg2=param2"
+        if util.py2k:
+            # just to make sure linters / formatters etc. don't erase the
+            # 'u' above
+            assert isinstance(url_str, unicode)  # noqa
+        u = url.make_url(url_str)
+        eq_(u.query, {"arg1": "param1", "arg2": "param2"})
+        eq_(u.database, "")
+        eq_(str(u), "dialect://user:pass@host/?arg1=param1&arg2=param2")
+
     def test_comparison(self):
         common_url = (
             "dbtype://username:password"