aiidateam / aiida-core

The official repository for the AiiDA code
https://aiida-core.readthedocs.io
Other
431 stars 187 forks source link

database password cannot contain `@` ? #6122

Closed Clarkszw closed 6 months ago

Clarkszw commented 1 year ago

Describe the bug

When I setup my profile, if the password of the postgres user is @abcde, which starts with @, it will throw this error with a wrong host name :

(aiida) a-zhiwenshi@LAPTOP-9CR8MMD0:/usr/local$ verdi setup
Report: enter ? for help.
Report: enter ! to ignore the default and set no value.
Profile name: 
Profile name: aiida
Email Address (for sharing data) [a-zhiwenshi@microsoft.com]: 
First name [Clark]: 
Last name [Shi]: 
Institution [Microsoft]: 
Database engine (postgresql_psycopg2) [postgresql_psycopg2]: 
Database backend (core.psql_dos) [core.psql_dos]: 
Database host [localhost]: 
Database port [5432]: 
Database name: aiidadb  
Database username: aiida
Database password: @abcd
Broker protocol (amqp, amqps) [amqp]: 
Broker username [guest]: 
Broker password [guest]: 
Broker host [127.0.0.1]: 
Broker port [5672]: 
Broker virtual host name []: 
Repository directory [/home/a-zhiwenshi/.aiida/repository/aiida]: 
Success: created new profile `aiida`.
Report: initialising the profile storage.
Critical: storage initialisation failed, probably because connection details are incorrect:
Could not connect to database: (psycopg2.OperationalError) could not translate host name "abcd@localhost" to address: Name or service not known

(Background on this error at: https://sqlalche.me/e/14/e3q8)

Your environment

ltalirz commented 1 year ago

That is a good point. AiiDA should probably urlencode the password before using it, like in https://stackoverflow.com/a/1424009/1069467

SharanRP commented 6 months ago

I’m attempting a certain process (as depicted in the attached image), but I’m uncertain if it’s the right approach. Since I’m a beginner with AiiDA, could you kindly assist me in resolving this issueimage

ltalirz commented 6 months ago

Hi @SharanRP , I suggest you search for create_engine in the AiiDA codebase and urlencode the password before passing it to that function, as in the StackOverflow post I linked https://github.com/search?q=repo%3Aaiidateam%2Faiida-core%20create_engine&type=code

Then, create a test with a password that includes the @ character; perhaps somewhere here https://github.com/aiidateam/aiida-core/blob/main/tests/cmdline/commands/test_setup.py#L204

SharanRP commented 6 months ago

@ltalirz, I've submitted a pull request addressing the changes you provided guidance on