Skip to content
New issue

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

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

Already on GitHub? # to your account

Traceback in SQL Commenter when an empty string is encountered #3308

Open
selcuk opened this issue Feb 28, 2025 · 0 comments · May be fixed by #3309
Open

Traceback in SQL Commenter when an empty string is encountered #3308

selcuk opened this issue Feb 28, 2025 · 0 comments · May be fixed by #3309
Labels
bug Something isn't working

Comments

@selcuk
Copy link

selcuk commented Feb 28, 2025

Describe your environment

OS: Debian, macOS
Python version: Python 3.12
Package version: 0.51b2
Django version: 5.1.6

What happened?

In some cases (in my case when psycopg3 connection pooling is enabled in a Django project) the SQL statement may be an empty string, which causes a traceback in the sqlcommenter.

Steps to Reproduce

Expected Result

No traceback.

Actual Result

Getting a traceback:

[2025-02-28 04:37:32,454] [__init__] [ERROR]: "Exception while generating sql comment: string index out of range"
Traceback (most recent call last):
  File "/Users/selcuk/src/testapp/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/dbapi/__init__.py", line 505, in _update_args_with_added_sql_comment
    statement = _add_sql_comment(args_list[0], **commenter_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/selcuk/src/testapp/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/sqlcommenter_utils.py", line 26, in _add_sql_comment
    if sql[-1] == ";":
       ~~~^^^^
IndexError: string index out of range

Additional context

No response

Would you like to implement a fix?

Yes

@selcuk selcuk added the bug Something isn't working label Feb 28, 2025
@selcuk selcuk linked a pull request Feb 28, 2025 that will close this issue
6 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant