Page MenuHomeSoftware Heritage
Paste P1173

(An Untitled Masterwork)
ActivePublic

Authored by douardda on Sep 22 2021, 6:15 PM.
 ddouard  (e) swh   master … 2  ~/s/s/swh-web  cat swh/web/django_db_backend/base.py
from django.db.backends.postgresql.base import * # NOQA
from django.db.backends.postgresql.base import DatabaseWrapper as _DatabaseWrapper
# dirty hack to allow using a postgresql:// libpq connection URI as db name...
# This allows to define the connection arguments in a pg_service file, put
# the credential in the pgpass file, etc.
class DatabaseWrapper(_DatabaseWrapper):
def get_connection_params(self):
if self.settings_dict.get("NAME", "").startswith("postgresql://"):
return {"dsn": self.settings_dict["NAME"]}
return super().get_connection_params()