Skip to content

Commit

Permalink
use new URL api for password obfuscate
Browse files Browse the repository at this point in the history
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: sqlalchemy#816
  • Loading branch information
zzzeek committed Mar 23, 2021
1 parent c18769f commit 00d050b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion alembic/util/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
7 changes: 7 additions & 0 deletions docs/build/unreleased/816.rst
Original file line number Diff line number Diff line change
@@ -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.

6 changes: 6 additions & 0 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 00d050b

Please sign in to comment.