From 34fee7be2d66de7b6cc7355919cd4e3f83b91b88 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 8 May 2025 08:34:21 -0400 Subject: [PATCH] dont render URL in unparseable URL error message The error message that is emitted when a URL cannot be parsed no longer includes the URL itself within the error message. Fixes: #12579 Change-Id: Icd17bd4fe0930036662b6a4fe0264cb13df04ba7 (cherry picked from commit aaa28f457eaa3f98c417666b4d0ad4d70ccb1ac0) --- doc/build/changelog/unreleased_20/12579.rst | 7 +++++++ lib/sqlalchemy/engine/url.py | 2 +- test/engine/test_parseconnect.py | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 doc/build/changelog/unreleased_20/12579.rst diff --git a/doc/build/changelog/unreleased_20/12579.rst b/doc/build/changelog/unreleased_20/12579.rst new file mode 100644 index 0000000000..70c619db09 --- /dev/null +++ b/doc/build/changelog/unreleased_20/12579.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, engine + :tickets: 12579 + + The error message that is emitted when a URL cannot be parsed no longer + includes the URL itself within the error message. + diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index bb004f11cd..20079a6b53 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -920,5 +920,5 @@ def _parse_url(name: str) -> URL: else: raise exc.ArgumentError( - "Could not parse SQLAlchemy URL from string '%s'" % name + "Could not parse SQLAlchemy URL from given URL string" ) diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 16b129fd8a..7c562bf39d 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -791,6 +791,13 @@ class CreateEngineTest(fixtures.TestBase): module=mock_dbapi, ) + def test_cant_parse_str(self): + with expect_raises_message( + exc.ArgumentError, + r"^Could not parse SQLAlchemy URL from given URL string$", + ): + create_engine("notarealurl") + def test_urlattr(self): """test the url attribute on ``Engine``.""" -- 2.47.3