-
Notifications
You must be signed in to change notification settings - Fork 22
Apply string interpolation in mogrify if args is not None #118
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
base: main
Are you sure you want to change the base?
Conversation
|
I'm going to be honest, I'm not sure this is a good idea. Our driver is based on PyMySQL and is compatible with its behaviors. This change would be a breaking change for any code that assumes those existing behaviors. |
|
I double checked and both PyMySQL and MySQLdb clients work the same way ours does. This way of doing parameters is also consistent with the way that Python itself works when printing strings with substitutions using the |
|
@kesmit13 yeah I also checked that that PyMySQL works this way. I've encountered this problem when developing SingleStore backend for Django - certain query templates with
|
|
@pmishchenko-ua I wonder how PyMySQL / mysqlclient work with Django if they work the same way? I'd like to avoid an option if possible, but I would rather do that than create a whole fork just for that one difference. |
|
@kesmit13 good question, I've double checked with Django, it works ot top of mysqlclient. It turns out that the key difference to our implementation is truthiness check vs "not None" check, so this is probably the fix. It won't break queries that don't pass I've updated PR description to reflect the actual fix. |
|
@pmishchenko-ua I'm going to have to go down memory lane to try to remember why I took that out in the first place. I do remember removing that. I don't recall if it was for SQLAlchemy or Ibis or something else... I believe the reason was that we support both positional and dictionary style substitution parameters and some package was sending an empty dict instead of None. |
|
@pmishchenko-ua It's possible that this was an artifact of when the SingleStoreDB client was a frontend to many other MySQL clients. At some point, we refactored and just made it a frontend for PyMySQL and the Data API, and dropped all of the others. I'll have to run some tests in SQLAlchemy and Ibis just to see if there is any affect there though. |
|
@pmishchenko-ua After thinking about this some more, I think a connection option might be the best way to go. I'm pretty leery of changing something that every query goes through. Odds are it would be fine, but there may be some customer with existing code that depends on the current behavior. I'd rather play it safe. |
b4e0b24 to
0ca30ce
Compare
0ca30ce to
5455c5e
Compare
| if conn.interpolate_query_with_empty_args: | ||
| should_interpolate = args is not None | ||
| else: | ||
| should_interpolate = bool(args) | ||
|
|
||
| if should_interpolate: |
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.
These lines of code appear in multiple places. It would be better to put them in a function in the singlestoredb/utils/mogrify.py file and use the function in the if block that needs it.
Currently the behavior of
executedepends on whether query arguments are non-empty, even when the result set is the same. Seetest_mogrify_val_with_percentas an example - without the change, the query with an empty parameters list produces incorrect result.