Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

unable to connect to postgres using unix socket #257

Closed

Description

@ugtar

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'

Activity

  1. ugtar commented on Oct 22, 2020

    @ugtar
    Author

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

  2. ugtar commented on Nov 4, 2020

    @ugtar
    Author

    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

  3. reopened this on Nov 4, 2020
  4. tabrezm commented on Jan 11, 2021

    @tabrezm

    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()
  5. ugtar commented on Jan 12, 2021

    @ugtar
    Author

    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.

  6. ugtar commented on Jan 12, 2021

    @ugtar
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions