Open m1kc opened 1 year ago
from django.db.backends.postgresql import base class DatabaseWrapper(base.DatabaseWrapper): def get_new_connection(self, conn_params): conn = super(DatabaseWrapper, self).get_new_connection(conn_params) if hasattr(conn, 'read_only'): # pyscopg3 conn.read_only = True elif hasattr(conn, 'set_session'): # pyscopg2 conn.set_session(readonly=True) else: raise RuntimeError("pg_readonly: unknown adapter type (only pyscopg2 and pyscopg3 are supported)") return conn