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

unable to connect to postgres using unix socket #257

Closed
ugtar opened this issue Oct 21, 2020 · 5 comments
Closed

unable to connect to postgres using unix socket #257

ugtar opened this issue Oct 21, 2020 · 5 comments

Comments

@ugtar
Copy link

ugtar commented Oct 21, 2020

since this change #210 there does not appear to be a way to connect to a postgres database using a unix socket. DatabaseURL is using urllib urlsplit to parse the dsn, but in the case of a unix socket, the hostname component will be empty since the "hostname" in case of a socket, begins with /. Prior to the mentioned PR that didn't seem to be a blocking issue since the url string itself was passed to the asyncpg backend, however, now the parsed components are sent instead.

urlquoting the hostname part to preserve the / doesn't work either since the hostname component is not unquoted

In [18]: d = databases.DatabaseURL("postgresql://foo:bar@/bleh:5432/somedb")                                            

In [19]: d.hostname        
                                                                                             
In [30]: d = databases.DatabaseURL(f"postgresql://foo:bar@{urllib.parse.quote_plus('/bleh')}:5432/somedb")              

In [31]: d.hostname                                                                                                     
Out[31]: '%2Fbleh'
@ugtar ugtar closed this as completed Oct 22, 2020
@ugtar
Copy link
Author

ugtar commented Oct 22, 2020

sorry, i didn't see the contributor guidelines.. i'll send a message in chat

@ugtar
Copy link
Author

ugtar commented Nov 4, 2020

I've posted messages in both gitter and discus and haven't gotten any response. As far as I can tell this is still an issue

@tabrezm
Copy link

tabrezm commented Jan 11, 2021

I'm using the following workaround until the regression can be fixed:

# monkey patch
import asyncpg


async def connect_patched(self) -> None:
    assert self._pool is None, "DatabaseBackend is already running"
    kwargs = self._get_connection_kwargs()
    self._pool = await asyncpg.create_pool(str(self._database_url), **kwargs)


# end monkey patch

import databases
database = databases.Database(database_url.__to_string__(hide_password=False))
database._backend.connect = types.MethodType(connect_patched, database._backend)
await database.connect()

@ugtar
Copy link
Author

ugtar commented Jan 12, 2021

I did actually attach a PR to fix this issue, but the tests are failing. I haven't bothered to fix those because I haven't heard anything from the maintainers and I don't know if it solves the issue the way they would have wanted.

@ugtar
Copy link
Author

ugtar commented Jan 12, 2021

this seems to be fixed by the fix for #250. closing...

@ugtar ugtar closed this as completed Jan 12, 2021
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

Successfully merging a pull request may close this issue.

2 participants