diff options
| -rw-r--r-- | doc/build/changelog/unreleased_20/9682.rst | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/url.py | 2 | ||||
| -rw-r--r-- | test/engine/test_parseconnect.py | 6 |
3 files changed, 13 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_20/9682.rst b/doc/build/changelog/unreleased_20/9682.rst new file mode 100644 index 000000000..bfd4b0664 --- /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 ea1e926e6..0315737d6 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 471201666..65cf6b5f1 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", @@ -215,6 +216,10 @@ class URLTest(fixtures.TestBase): ) 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): |
