]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
indicate private use of URL.__new__ privately only
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Oct 2021 17:18:41 +0000 (13:18 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Oct 2021 17:25:16 +0000 (13:25 -0400)
Fixed issue where the deprecation warning for the :class:`.URL` constructor
which indicates that the :meth:`.URL.create` method should be used would
not emit if a full positional argument list of seven arguments were passed;
additionally, validation of URL arguments will now occur if the constructor
is called in this way, which was being skipped previously.

Fixes: #7130
Change-Id: I8c8491d8aa7774afaf67c22b4f8e9859f780f2d9

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

diff --git a/doc/build/changelog/unreleased_14/7130.rst b/doc/build/changelog/unreleased_14/7130.rst
new file mode 100644 (file)
index 0000000..f2bfb77
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, engine
+    :tickets: 7130
+
+    Fixed issue where the deprecation warning for the :class:`.URL` constructor
+    which indicates that the :meth:`.URL.create` method should be used would
+    not emit if a full positional argument list of seven arguments were passed;
+    additionally, validation of URL arguments will now occur if the constructor
+    is called in this way, which was being skipped previously.
index d91f0601138d9bb5a4ab1169007ed9e8dde5cba2..488f7395270f105268b4ee447c9acfcf605a620d 100644 (file)
@@ -85,7 +85,7 @@ class URL(
     """
 
     def __new__(self, *arg, **kw):
-        if not kw and len(arg) == 7:
+        if kw.pop("_new_ok", False):
             return super(URL, self).__new__(self, *arg, **kw)
         else:
             util.warn_deprecated(
@@ -151,6 +151,7 @@ class URL(
             cls._assert_port(port),
             cls._assert_none_str(database, "database"),
             cls._str_dict(query),
+            _new_ok=True,
         )
 
     @classmethod
@@ -466,6 +467,7 @@ class URL(
                     for key in set(self.query).difference(names)
                 }
             ),
+            _new_ok=True,
         )
 
     @util.memoized_property
index 136695279aa3236f919f88f910fa47685d65ac21..67d8369b5dc00ab801d26bdf21318334ad9b5006 100644 (file)
@@ -367,6 +367,49 @@ class URLTest(fixtures.TestBase):
             )
         eq_(u1, url.make_url("somedriver://user@hostname:52"))
 
+    def test_deprecated_constructor_all_args(self):
+        """test #7130"""
+        with testing.expect_deprecated(
+            r"Calling URL\(\) directly is deprecated and will be "
+            "disabled in a future release."
+        ):
+            u1 = url.URL(
+                "somedriver",
+                "user",
+                "secret",
+                "10.20.30.40",
+                1234,
+                "DB",
+                {"key": "value"},
+            )
+        eq_(
+            u1,
+            url.make_url(
+                "somedriver://user:secret@10.20.30.40:1234/DB?key=value"
+            ),
+        )
+
+    @testing.requires.python3
+    def test_arg_validation_all_seven_posn(self):
+        """test #7130"""
+        with testing.expect_deprecated(
+            r"Calling URL\(\) directly is deprecated and will be "
+            "disabled in a future release."
+        ):
+
+            assert_raises_message(
+                TypeError,
+                "drivername must be a string",
+                url.URL,
+                b"somedriver",
+                "user",
+                "secret",
+                "10.20.30.40",
+                1234,
+                "DB",
+                {"key": "value"},
+            )
+
     def test_deprecated_translate_connect_args_names(self):
         u = url.make_url("somedriver://user@hostname:52")