Skip to content

Fix TypeError when completion metadata is bytes#1612

Open
Sanjays2402 wants to merge 1 commit into
dbcli:mainfrom
Sanjays2402:fix/escape-name-bytes
Open

Fix TypeError when completion metadata is bytes#1612
Sanjays2402 wants to merge 1 commit into
dbcli:mainfrom
Sanjays2402:fix/escape-name-bytes

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #1405

Description

When the client encoding is one psycopg cannot decode (e.g. SQL_ASCII), catalog identifiers come back as bytes. PGCompleter.escape_name matched a str regex against them and raised TypeError: cannot use a string pattern on a bytes-like object, which killed the completion_refresh thread so completions never loaded. It now decodes bytes with the replace error handler first, matching the PGCLIENTENCODING=utf8 workaround users found.

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected (new parametrized test fails 4/4 on main with the reported TypeError and passes with the fix; tests/test_pgcompleter.py plus the completion suites are green, ruff check/format clean).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

When the client encoding is one psycopg cannot decode (e.g. SQL_ASCII),
catalog identifiers such as schema names come back as bytes. escape_name
then matched a str regex against them and raised
"TypeError: cannot use a string pattern on a bytes-like object", killing
the completion_refresher thread so completions never loaded.

escape_name now decodes bytes with the replacement error handler before
matching, so completion degrades gracefully instead of crashing.

Closes dbcli#1405
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.

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

1 participant