Skip to content

Commit 4eb62f5

Browse files
BillionClawBillionClaw
andauthored
fix: respect DSN password over PGPASSWORD env var (#1562)
Co-authored-by: BillionClaw <dev@billionclaw.io>
1 parent da3a760 commit 4eb62f5

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

pgcli/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,13 @@ def connect(self, database="", host="", user="", port="", passwd="", dsn="", **k
633633
# If password prompt is not forced but no password is provided, try
634634
# getting it from environment variable.
635635
if not self.force_passwd_prompt and not passwd:
636-
passwd = os.environ.get("PGPASSWORD", "")
636+
if dsn:
637+
# Check if DSN contains a password - if so, don't use PGPASSWORD
638+
parsed_dsn = conninfo_to_dict(dsn)
639+
if "password" not in parsed_dsn:
640+
passwd = os.environ.get("PGPASSWORD", "")
641+
else:
642+
passwd = os.environ.get("PGPASSWORD", "")
637643

638644
# Prompt for a password immediately if requested via the -W flag. This
639645
# avoids wasting time trying to connect to the database and catching a

0 commit comments

Comments
 (0)