From 040e0d2560c17ff490b2b0bbe193c7658d3b4603 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Fri, 21 Apr 2023 22:26:11 +0200 Subject: [PATCH] Fixed bug in `URL.normalized_query` Fixed a bug that prevented use of :attr:`_engine.URL.normalized_query` in SQLAlchemy v2. Fixes: #9682 Change-Id: I2704154af34f438b4cbb290602fc936c1184c074 --- doc/build/changelog/unreleased_20/9682.rst | 6 ++++++ lib/sqlalchemy/engine/url.py | 2 +- test/engine/test_parseconnect.py | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 doc/build/changelog/unreleased_20/9682.rst diff --git a/doc/build/changelog/unreleased_20/9682.rst b/doc/build/changelog/unreleased_20/9682.rst new file mode 100644 index 0000000000..bfd4b06640 --- /dev/null +++ b/doc/build/changelog/unreleased_20/9682.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, engine + :tickets: 9682 + + Fixed a bug that prevented use of :attr:`_engine.URL.normalized_query` in + SQLAlchemy v2. diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index ea1e926e62..0315737d66 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -564,7 +564,7 @@ class URL(NamedTuple): ), ) - @util.memoized_property + @property def normalized_query(self) -> Mapping[str, Sequence[str]]: """Return the :attr:`_engine.URL.query` dictionary with values normalized into sequences. diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 471201666d..65cf6b5f1f 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -179,6 +179,7 @@ class URLTest(fixtures.TestBase): def test_query_string(self): u = url.make_url("dialect://user:pass@host/db?arg1=param1&arg2=param2") eq_(u.query, {"arg1": "param1", "arg2": "param2"}) + eq_(u.normalized_query, {"arg1": ("param1",), "arg2": ("param2",)}) eq_( u.render_as_string(hide_password=False), "dialect://user:pass@host/db?arg1=param1&arg2=param2", @@ -214,6 +215,10 @@ class URLTest(fixtures.TestBase): "dialect://user:pass@host/db?arg1=param1&arg2=param2&arg2=param3" ) eq_(u.query, {"arg1": "param1", "arg2": ("param2", "param3")}) + eq_( + u.normalized_query, + {"arg1": ("param1",), "arg2": ("param2", "param3")}, + ) eq_( u.render_as_string(hide_password=False), "dialect://user:pass@host/db?arg1=param1&arg2=param2&arg2=param3", @@ -222,6 +227,7 @@ class URLTest(fixtures.TestBase): test_url = "dialect://user:pass@host/db?arg1%3D=param1&arg2=param+2" u = url.make_url(test_url) eq_(u.query, {"arg1=": "param1", "arg2": "param 2"}) + eq_(u.normalized_query, {"arg1=": ("param1",), "arg2": ("param 2",)}) eq_(u.render_as_string(hide_password=False), test_url) def test_comparison(self): -- 2.39.5