8000 Handle psycopg2's string composition by bmdavi3 · Pull Request #170 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

Handle psycopg2's string composition #170

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

Merged
merged 3 commits into from Nov 15, 2018
Merged

Handle psycopg2's string composition #170

merged 3 commits into from Nov 15, 2018

Conversation

bmdavi3
Copy link
Contributor
@bmdavi3 bmdavi3 commented Nov 15, 2018

Something like this would probably work for #169

@codecov-io
Copy link
codecov-io commented Nov 15, 2018

Codecov Report

Merging #170 into master will decrease coverage by 4.62%.
The diff coverage is 70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #170      +/-   ##
==========================================
- Coverage    80.3%   75.68%   -4.63%     
==========================================
  Files          28       28              
  Lines        2366     2340      -26     
  Branches      400      394       -6     
==========================================
- Hits         1900     1771     -129     
- Misses        309      423     +114     
+ Partials      157      146      -11
Impacted Files Coverage Δ
sentry_sdk/integrations/django/__init__.py 83.72% <70%> (+4.57%) ⬆️
sentry_sdk/integrations/sanic.py 0% <0%> (-79.49%) ⬇️
sentry_sdk/integrations/aws_lambda.py 0% <0%> (-17.95%) ⬇️
sentry_sdk/scope.py 75% <0%> (-3.71%) ⬇️
sentry_sdk/integrations/django/transactions.py 85.91% <0%> (-2.82%) ⬇️
sentry_sdk/integrations/modules.py 87.5% <0%> (-0.97%) ⬇️
sentry_sdk/integrations/argv.py 92.85% <0%> (-0.9%) ⬇️
sentry_sdk/integrations/excepthook.py 86.36% <0%> (-0.6%) ⬇️
sentry_sdk/integrations/atexit.py 92.85% <0%> (-0.48%) ⬇️
sentry_sdk/integrations/rq.py 78% <0%> (-0.44%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ab6d78...8060afd. Read the comment docs.

def sql_to_string(sql):
return sql

import psycopg2.sql
Copy link
Member

Choose a reason for hiding this comment

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

I think this line is not intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha. Correct, will update.

@untitaker
Copy link
Member

apart from one comment lgtm! I am not sure how to test this though. I'd like to

return sql
except ImportError:
def sql_to_string(sql):
return sql

Choose a reason for hiding this comment

The reason will be disp 8000 layed to describe this comment to others. Learn more.

I'd prefer the full try/except/else blocks so there's less in the try:

try:
    import psycopg2.sql
except ImportError:
    def sql_to_string(sql):
        return sql
else:
    # Handle psycopg2 sql object strings (or some such comment)
    def sql_to_string(sql):
        if isinstance(sql, psycopg2.sql.SQL):
            return sql.string
        return sql

Copy link
Member

Choose a reason for hiding this comment

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

it's fine, just a function declaration whose errors are caught

@bmdavi3
Copy link
Contributor Author
bmdavi3 commented Nov 15, 2018

Let me see if I can come up with a test to exercise this.

@untitaker
Copy link
Member

@bmdavi3 can you run black over that file, I think it's misformatted

@untitaker untitaker merged commit b8699bf into getsentry:master Nov 15, 2018
@untitaker
Copy link
Member

Thanks! I think it'd be pretty hard to test this realistically. If you want to give it a shot at a later point feel free to

@bmdavi3
Copy link
Contributor Author
bmdavi3 commented Nov 15, 2018

I'm not sure if they are what you had in mind, but I did add a couple tests in the last commit. They're not super laser focused, in that they don't call format_sql() directly, or the try / except block itself even, but they do end up hitting the call to sql_to_string(sql), and would fail without the changes introduced in this p.r.

@untitaker
Copy link
Member

Yeah, just noticed... they break pypy. I'll figure out a fix. Thanks!

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.

4 participants
0