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

1.3.8: unicode_literal always adding the _binary prefix #123

Closed
claudep opened this issue Sep 30, 2016 · 4 comments
Closed

1.3.8: unicode_literal always adding the _binary prefix #123

claudep opened this issue Sep 30, 2016 · 4 comments

Comments

@claudep
Copy link

claudep commented Sep 30, 2016

After the commit 2617620, unicode_literal is always adding the _binary prefix because db.literal inside unicode_literal is called on the encoded value (and encoded values are always bytes).
This is a serious regression!

@methane
Copy link
Member

methane commented Sep 30, 2016

Sorry, but could you describe more detail?

Is this problem is on Python 3 only? or Python 2 only? both?

Original report (#106 (comment) ) was on Python 3.5.

because db.literal inside unicode_literal is called on the encoded value (and encoded values are always bytes).

What the "encoded value" exactly means?

@claudep
Copy link
Author

claudep commented Sep 30, 2016

My debug session was on Python 3, but it might happen on Python 2 too.
See this line (inside def _get_unicode_literal()):

return db.literal(str(u).encode(unicode_literal.charset))

Before the patch, db.literal was using string_literal even for bytes, now it uses bytes_literal, so as str(u).encode(unicode_literal.charset) is always bytes, the return value is always prepended with _binary, while the original value is unicode.

@claudep
Copy link
Author

claudep commented Sep 30, 2016

The solution might be to replace

return db.literal(str(u).encode(unicode_literal.charset))

by

return db.string_literal(str(u).encode(unicode_literal.charset))

And probably the same for Python 2.

@vtermanis
Copy link
Contributor

vtermanis commented Sep 30, 2016

@claudep: I think that is the right solution and is an oversight I made when suggesting the original change.

@methane methane closed this as completed Oct 11, 2016
vtermanis added a commit to vtermanis/mysqlclient-python that referenced this issue Jan 7, 2017
fix falsely prefixing strings with _binary type identifier (PyMySQL#123)
vtermanis added a commit to vtermanis/mysqlclient-python that referenced this issue Jan 7, 2017
- Based on PyMySQL#106 but now disabled by default
- Can be enabled via 'binary_prefix' connection parameter
- Added unit tests to verify behaviour

fix falsely prefixing strings with _binary type identifier (PyMySQL#123)
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

No branches or pull requests

3 participants