do not use str(url) to stringify a URL for subsequent use

The str(url) function in SQLAlchemy hides the password.
For a URL string that is to be re-used, use
render_as_string(hide_password=False).

Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I27eb13459820ce4c7c48e91c780f31549ee0d8af
This commit is contained in:
Takashi Kajinami 2024-05-16 00:19:44 +09:00
parent 47f8c9b3da
commit f861467b7f

View File

@ -69,8 +69,10 @@ class BaseWalkMigrationTestCase(object):
database functionality (reset default settings and session cleanup).
"""
CONF.set_override('uri', str(engine.url),
group='drivers:management_store:sqlalchemy')
CONF.set_override(
'uri',
engine.url.render_as_string(hide_password=False),
group='drivers:management_store:sqlalchemy')
def _alembic_command(self, alembic_command, engine, *args, **kwargs):
"""Most of alembic command return data into output.
@ -78,8 +80,10 @@ class BaseWalkMigrationTestCase(object):
We should redefine this setting for getting info.
"""
self.ALEMBIC_CONFIG.stdout = buf = io.StringIO()
CONF.set_override('uri', str(engine.url),
group='drivers:management_store:sqlalchemy')
CONF.set_override(
'uri',
engine.url.render_as_string(hide_password=False),
group='drivers:management_store:sqlalchemy')
getattr(command, alembic_command)(*args, **kwargs)
res = buf.getvalue().strip()
@ -180,8 +184,10 @@ class TestModelsMigrationsSync(t_m.ModelsMigrationsSync):
return self.engine
def db_sync(self, engine):
CONF.set_override('uri', str(engine.url),
group='drivers:management_store:sqlalchemy')
CONF.set_override(
'uri',
engine.url.render_as_string(hide_password=False),
group='drivers:management_store:sqlalchemy')
script_location = os.path.join(self.mg_path, 'alembic_migrations')
self.ALEMBIC_CONFIG.set_main_option('script_location', script_location)
alembic.command.upgrade(self.ALEMBIC_CONFIG, 'head')