From 00d050b4e4ff711a0730cb5ab39ef655bc55f00a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 23 Mar 2021 09:40:27 -0400 Subject: [PATCH] use new URL api for password obfuscate Fixed regression caused by SQLAlchemy 1.4 where the "alembic current" command would fail due to changes in the ``URL`` object. Change-Id: Ic0023885188c75ace19035adcf4c11c7bd10a843 Fixes: #816 --- alembic/util/messaging.py | 6 +++++- docs/build/unreleased/816.rst | 7 +++++++ tests/test_command.py | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 docs/build/unreleased/816.rst diff --git a/alembic/util/messaging.py b/alembic/util/messaging.py index 38a3f13e..29442d81 100644 --- a/alembic/util/messaging.py +++ b/alembic/util/messaging.py @@ -5,6 +5,7 @@ from sqlalchemy.engine import url +from . import sqla_compat from .compat import binary_type from .compat import collections_abc from .compat import string_types @@ -64,7 +65,10 @@ def err(message): def obfuscate_url_pw(u): u = url.make_url(u) if u.password: - u.password = "XXXXX" + if sqla_compat.sqla_14: + u = u.set(password="XXXXX") + else: + u.password = "XXXXX" return str(u) diff --git a/docs/build/unreleased/816.rst b/docs/build/unreleased/816.rst new file mode 100644 index 00000000..9ce24256 --- /dev/null +++ b/docs/build/unreleased/816.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, environment + :tickets: 816 + + Fixed regression caused by SQLAlchemy 1.4 where the "alembic current" + command would fail due to changes in the ``URL`` object. + diff --git a/tests/test_command.py b/tests/test_command.py index 8350e829..6fb99579 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -252,6 +252,12 @@ def test_plain_current(self): with self._assert_lines(["a3"]): command.current(self.cfg) + def test_current_obfuscate_password(self): + eq_( + util.obfuscate_url_pw("postgresql://scott:tiger@localhost/test"), + "postgresql://scott:XXXXX@localhost/test", + ) + def test_two_heads(self): command.stamp(self.cfg, ()) command.stamp(self.cfg, (self.a1.revision, self.b1.revision))