Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect DSN doesn't handle @ in username #593

Closed
rudigiesler opened this issue Jun 19, 2020 · 1 comment
Closed

Connect DSN doesn't handle @ in username #593

rudigiesler opened this issue Jun 19, 2020 · 1 comment

Comments

@rudigiesler
Copy link

  • asyncpg version: 0.20.1
  • PostgreSQL version: 9.6
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : Azure PostgreSQL. It is reproducible with a local install.
  • Python version: 3.7.7
  • Platform: Docker/Debian, locally OSX
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: N/A, installed from wheel.
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Yes

Azure managed databases have credentials as follows:
url: instance-name.privatelink.postgres.database.azure.com
database: db-name
username: db-name@instance-name
password: password

Combining that into a DSN, we get something like:
postgres://db-name@instance-name:[email protected]:5432/db-name

But the utility to interpret the DSN makes a mistake when trying to interpret a DSN of this shape:

  File "/turn-rasa-connector/turn_rasa_connector/turn.py", line 163, in get_postgresql_pool
    self._postgresql_pool = await asyncpg.create_pool(self.postgresql_url)
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/pool.py", line 398, in _async__init__
    await self._initialize()
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/pool.py", line 426, in _initialize
    await first_ch.connect()
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/pool.py", line 125, in connect
    self._con = await self._pool._get_new_connection()
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/pool.py", line 472, in _get_new_connection
    **self._connect_kwargs)
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/connection.py", line 1677, in connect
    max_cacheable_statement_size=max_cacheable_statement_size)
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 645, in _connect
    addrs, params, config = _parse_connect_arguments(timeout=timeout, **kwargs)
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 496, in _parse_connect_arguments
    server_settings=server_settings)
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 236, in _parse_connect_dsn_and_args
    host, port = _parse_hostlist(dsn_hostspec, port, unquote=True)
  File "/opt/venv/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 196, in _parse_hostlist
    hostlist_ports.append(int(hostspec_port))
ValueError: invalid literal for int() with base 10: '[email protected]:5432'

It seems like it is taking the first @ symbol when splitting between the instance name and credentials, instead of the last @ symbol.

This also happens locally when creating a user that has an @ symbol in the username.

@rudigiesler
Copy link
Author

I see this was solved in #472 , and percent encoding should be used instead. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant