diff --git a/src/aiida/storage/psql_dos/utils.py b/src/aiida/storage/psql_dos/utils.py index 8fa50053b1..f1bf0aa4dd 100644 --- a/src/aiida/storage/psql_dos/utils.py +++ b/src/aiida/storage/psql_dos/utils.py @@ -31,17 +31,20 @@ def create_sqlalchemy_engine(config: PsqlConfig): See https://docs.sqlalchemy.org/en/13/core/engines.html?highlight=create_engine#sqlalchemy.create_engine for more info. """ + from urllib.parse import quote_plus + from sqlalchemy import create_engine # The hostname may be `None`, which is a valid value in the case of peer authentication for example. In this case # it should be converted to an empty string, because otherwise the `None` will be converted to string literal "None" hostname = config['database_hostname'] or '' separator = ':' if config['database_port'] else '' + password = quote_plus(config['database_password']) engine_url = 'postgresql://{user}:{password}@{hostname}{separator}{port}/{name}'.format( separator=separator, user=config['database_username'], - password=config['database_password'], + password=password, hostname=hostname, port=config['database_port'], name=config['database_name'], diff --git a/tests/cmdline/commands/test_setup.py b/tests/cmdline/commands/test_setup.py index 613e77dbb6..6f5a693c6e 100644 --- a/tests/cmdline/commands/test_setup.py +++ b/tests/cmdline/commands/test_setup.py @@ -207,7 +207,7 @@ def test_setup(self): postgres.determine_setup() db_name = 'aiida_test_setup' db_user = 'aiida_test_setup' - db_pass = 'aiida_test_setup' + db_pass = '@aiida_test_setup' postgres.create_dbuser(db_user, db_pass) postgres.create_db(db_user, db_name)