From: Mike Bayer Date: Fri, 1 Oct 2021 17:18:41 +0000 (-0400) Subject: indicate private use of URL.__new__ privately only X-Git-Tag: rel_1_4_26~49^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f7c0f4ee1c4218fb72dccb7c5176042902c803a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git indicate private use of URL.__new__ privately only 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 --- diff --git a/doc/build/changelog/unreleased_14/7130.rst b/doc/build/changelog/unreleased_14/7130.rst new file mode 100644 index 0000000000..f2bfb777d9 --- /dev/null +++ b/doc/build/changelog/unreleased_14/7130.rst @@ -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. diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index d91f060113..488f739527 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -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 diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 136695279a..67d8369b5d 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -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")