As str(url) will be changing to obfuscate the PW,
use SQLA 1.3 / 1.4 / 2.0 functionality directly.
Change-Id: I4694cc6d2ed7f0463fe0fae8a93ee9ec5df74760
References: https://github.com/sqlalchemy/sqlalchemy/issues/8567
def obfuscate_url_pw(input_url: str) -> str:
u = url.make_url(input_url)
- if u.password:
- if sqla_compat.sqla_14:
- u = u.set(password="XXXXX")
- else:
- u.password = "XXXXX" # type: ignore[misc]
- return str(u)
+ return sqla_compat.url_render_as_string(u, hide_password=True)
def warn(msg: str, stacklevel: int = 2) -> None:
yield
+def url_render_as_string(url, hide_password=True):
+ if sqla_14:
+ return url.render_as_string(hide_password=hide_password)
+ else:
+ return url.__to_string__(hide_password=hide_password)
+
+
def _safe_begin_connection_transaction(
connection: "Connection",
) -> "Transaction":
def test_current_obfuscate_password(self):
eq_(
util.obfuscate_url_pw("postgresql://scott:tiger@localhost/test"),
- "postgresql://scott:XXXXX@localhost/test",
+ "postgresql://scott:***@localhost/test",
)
def test_two_heads(self):