Skip to content

fix: decode bytes from conn.info.get_parameters() to avoid TypeError on macOS#1598

Closed
xxiaoxiong wants to merge 1 commit into
dbcli:mainfrom
xxiaoxiong:fix/decode-bytes-dsn-parameters-1518
Closed

fix: decode bytes from conn.info.get_parameters() to avoid TypeError on macOS#1598
xxiaoxiong wants to merge 1 commit into
dbcli:mainfrom
xxiaoxiong:fix/decode-bytes-dsn-parameters-1518

Conversation

@xxiaoxiong
Copy link
Copy Markdown

Problem

pgcli crashes on startup on macOS (Homebrew, Python 3.13+/3.14+) with:

TypeError: replace() argument 2 must be str, not bytes

And in the completion refresher thread:

TypeError: cannot use a string pattern on a bytes-like object

Root Cause

psycopg.Connection.info.get_parameters() can return a dictionary with bytes values instead of str on certain platforms (macOS with Homebrew psycopg, Python 3.13+). This occurs because psycopg's parameter_status returns raw bytes from the PostgreSQL protocol, and get_parameters() passes them through without decoding.

When host is b'localhost' instead of 'localhost', downstream code in main.py's get_prompt() calls string.replace("\\H", self.pgexecute.host) which raises TypeError because str.replace() requires str arguments.

Similarly, search_path() returns raw cursor results that can be bytes, causing pgcompleter.py's escape_name() to fail with TypeError: cannot use a string pattern on a bytes-like object.

Changes

  1. pgcli/pgexecute.py - connect() method: After calling conn.info.get_parameters(), decode any bytes values to str using .decode().

  2. pgcli/pgexecute.py - search_path() method: Decode individual schema name values from bytes to str if needed.

Closes

Closes #1518

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@dbaty
Copy link
Copy Markdown
Member

dbaty commented May 31, 2026

Hello. Thanks for your contribution. But did you actually reproduce the bug on your machine? Or is this just you blinding running your AI agent on pgcli amongst dozens of projects?

Co-maintainers: A user actually made some inquiry about this bug here. I find that more promising than this pull request. I'll try to in the coming days weeks (let's not overpromise, shall we?).

@xxiaoxiong xxiaoxiong closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startup crashes on TypeError: replace() argument 2 must be str, not bytes, followed by TypeError: cannot use a string pattern on a bytes-like object

2 participants