]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix url.make_url
authorsemen603089 <semen603089@mail.ru>
Wed, 12 Jul 2023 17:56:03 +0000 (13:56 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Wed, 12 Jul 2023 17:56:03 +0000 (13:56 -0400)
<!-- Provide a general summary of your proposed changes in the Title field above -->

### Description
<!-- Describe your changes in detail -->

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

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: #<issue number>` 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: #<issue number>` 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

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

diff --git a/doc/build/changelog/unreleased_20/10079.rst b/doc/build/changelog/unreleased_20/10079.rst
new file mode 100644 (file)
index 0000000..1bee097
--- /dev/null
@@ -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
index 0315737d660a2cd3f7e4663eadfd9ba752f8aff9..5cf5ec7b4b7df72078eb975534388d24d8888fa6 100644 (file)
@@ -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
 
index 334b7aeb9c344c94417d18067ef49b9eba838939..4c144a4a31afde0dc3418a88dc605390d84266fc 100644 (file)
@@ -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",