From: semen603089 Date: Wed, 12 Jul 2023 17:56:03 +0000 (-0400) Subject: Fix url.make_url X-Git-Tag: rel_2_0_19~4^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a35afb5ce7da55982571767af8b306fb51efba88;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix url.make_url ### Description ### Checklist This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [X] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. Fixes #10079 **Have a nice day!** Closes: #10080 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10080 Pull-request-sha: 133c7d6c35a75f23089fd4b1c0438f1a4640a924 Change-Id: Ie3d998385743680756bc10fbb4f4227669d57648 --- diff --git a/doc/build/changelog/unreleased_20/10079.rst b/doc/build/changelog/unreleased_20/10079.rst new file mode 100644 index 0000000000..1bee0977fb --- /dev/null +++ b/doc/build/changelog/unreleased_20/10079.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, engine + :tickets: 10079 + + The behavior of the :func:`make_url` has been changed. + Now if you pass an incorrect argument type to the :func:`make_url`, + an ArgumentError error will be thrown. + Correct argument types is: str, URL \ No newline at end of file diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 0315737d66..5cf5ec7b4b 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -836,6 +836,12 @@ def make_url(name_or_url: Union[str, URL]) -> URL: if isinstance(name_or_url, str): return _parse_url(name_or_url) + elif not isinstance(name_or_url, URL) and not hasattr( + name_or_url, "_sqla_is_testing_if_this_is_a_mock_object" + ): + raise exc.ArgumentError( + f"Expected string or URL object, got {name_or_url!r}" + ) else: return name_or_url diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 334b7aeb9c..4c144a4a31 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -322,6 +322,13 @@ class URLTest(fixtures.TestBase): with expect_raises_message(TypeError, ".*immutable"): url_obj.query["foo"] = "hoho" + def test_create_engine_url_invalid(self): + with expect_raises_message( + exc.ArgumentError, + "Expected string or URL object, got 42", + ): + create_engine(42) + @testing.combinations( ( "foo1=bar1&foo2=bar2",