Skip to content

Commit

Permalink
Fix passwords containing @ not being accepted for Postgres databases (
Browse files Browse the repository at this point in the history
#6304)

The password was not quoted and so would be mistaken for the separator
of the username and hostname.
  • Loading branch information
SharanRP authored Mar 3, 2024
1 parent 0dee9d8 commit d14c14d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/aiida/storage/psql_dos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion tests/cmdline/commands/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d14c14d

Please sign in to comment.