Skip to content

Commit

Permalink
Preserve PGCLIENTENCODING before setting client_encoding=auto
Browse files Browse the repository at this point in the history
Follow-up d91a364
  • Loading branch information
dlax committed Mar 15, 2023
1 parent 190e5e0 commit ac4331a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pgactivity/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ def load(self, data: Buffer) -> str:
return data.decode(errors="replace")

def connect(dsn: str, **kwargs: Any) -> Connection:
# Set client_encoding to 'auto', if unset by the user.
# This is (more or less) what's done by psql.
conninfo = conninfo_to_dict(dsn)
conninfo.setdefault("client_encoding", "auto")
dsn = make_conninfo(**conninfo)
if "PGCLIENTENCODING" not in os.environ:
# Set client_encoding to 'auto', if not set by the user.
# This is (more or less) what's done by psql.
conninfo = conninfo_to_dict(dsn)
conninfo.setdefault("client_encoding", "auto")
dsn = make_conninfo(**conninfo)
conn = psycopg.connect(dsn, autocommit=True, row_factory=dict_row, **kwargs)
if conn.info.encoding == "ascii":
# If client encoding is still 'ascii', fall back to a loader with a replace
Expand Down

0 comments on commit ac4331a

Please sign in to comment.