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

Fix extract_signature when sql is a bytes object #366

Closed
wants to merge 4 commits into from

Conversation

ellisvalentiner
Copy link
Contributor

In psycopg2's execute_batch and execute_values functions, the SQL statement is a bytes object and not a string (see psycopg2's extras.py#L1198). This may also be a problem for other database adapters but I'm only aware of this behavior with psycopg2.

extract_signature raises a TypeError when the sql parameter is a bytes object because sql.find(" ") expects a bytes object and " " is a string.

My proposed solution is to check whether sql is a bytes object and decode if necessary.

I have signed the CLA.

@elasticmachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

1 similar comment
@elasticmachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

Copy link
Contributor

@beniwohli beniwohli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, thanks @ellisvalentiner! I left just a little suggestion up top!

elasticapm/instrumentation/packages/dbapi2.py Outdated Show resolved Hide resolved
@beniwohli beniwohli closed this in f752181 Dec 24, 2018
@beniwohli
Copy link
Contributor

Thanks for the fix @ellisvalentiner, it's now merged to master (after cleaning up a test that now failed), and I will push a release later today

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.

3 participants