Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle logging queries encoded as bytes under PostgreSQL #1812

Merged
merged 1 commit into from Jul 7, 2023

Conversation

Lucidiot
Copy link
Contributor

@Lucidiot Lucidiot commented Jul 7, 2023

Description

Unlike SQLite, psycopg supports queries encoded as bytes, and uses this in its own methods such as in execute_values. But the SQL logging only expects strings or Composables. This was causing an AttributeError such as this:

Traceback (most recent call last):
[snip]
  File "/home/lucidiot/.virtualenvs/tmp/lib/python3.10/site-packages/psycopg2/extras.py", line 1270, in execute_values
    cur.execute(b''.join(parts))
  File "/home/lucidiot/.virtualenvs/tmp/lib/python3.10/site-packages/debug_toolbar/panels/sql/tracking.py", line 246, in execute
    return self._record(super().execute, sql, params)
  File "/home/lucidiot/.virtualenvs/tmp/lib/python3.10/site-packages/debug_toolbar/panels/sql/tracking.py", line 181, in _record
    sql = sql.as_string(conn)
AttributeError: 'bytes' object has no attribute 'as_string'

This adds an extra condition to decode a bytes instance with .decode() instead of .as_string().

Fixes #987

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

@matthiask matthiask merged commit acd69df into jazzband:main Jul 7, 2023
20 checks passed
@matthiask
Copy link
Member

Thank you!

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.

Error when recording SQL queries that are byte-strings
2 participants