-
Notifications
You must be signed in to change notification settings - Fork 552
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
def sql_to_string(sql): | ||
return sql | ||
|
||
import psycopg2.sql |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha. Correct, will update.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Let me see if I can come up with a test to exercise this. |
@bmdavi3 can you run |
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 |
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. |
Yeah, just noticed... they break pypy. I'll figure out a fix. Thanks! |
Something like this would probably work for #169