0.4.0: Failing to use HA postgresql connection string
Before the release of 0.4.0:
We were able to use high available postgres connection string.
postgresql://user:password@host1,host2:port/dbname
After the release of 0.4.0:
We are not able to use the high available postgres connection string given above. After looking at the code and changes. We found that this particular PR: https://github.com/encode/databases/pull/210 is breaking the change.
Any help would be appreciated regarding this issue!
Hey @sukratkashyap sorry for this regression. I just did not know it was possible, another example of https://xkcd.com/1172/ :laughing: Seriously though, I clearly see that the surrounding code assumes a single endpoint. The specified high available DSN used to parse to something without errors by pure luck.
The workaround that I can recommend is registering a new backend with overridden connect().
from databases import Database
from databases.backends.postgres import PostgresBackend
class HighAvailablePostgresBackend(PostgresBackend):
async def connect(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)
Database.SUPPORTED_BACKENDS["hapostgresql"] = "my.package.module.HighAvailablePostgresBackend"
ha_db = Database("hapostgresql://user:password@host1,host2:port/dbname")