You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mysqlclient automatically decodes the string. But you override it so mysqlclient doesn't decode the string anymore. But a bug in mysqlclient (#343) hided your bug. Fixing #343 revealed your bug.
I hate converter. It is source of tons of bugs. It is not tested well. Overriding converter will cause surprising bugs like yours.
Yes, I agree. That was an attempt to fix ascii decoding errors appeared nobody knows when and where. Most probable candidates are sphinxsearch update from 2.3.x to 3.1.x and mysqlclient bugfixes.
I tried to enable use_unicode flag without converter, but I have 1 single error left:
AssertionError: 'за вдв' != 'за вдв'
Russian characters are not decoded correctly. Do you have any ideas, how to determine cause of with error (sphinxsearch vs mysqlclient usage)?
mysql> select attr_string from sphinx___testapp_testmodel where id = 2;
+-------------+
| attr_string |
+-------------+
| за вдв |
+-------------+
1 row in set (0.00 sec)
What is the difference of using converters vs use_unicode for strings?
Tried already, no errors.
I mean, in MySQL CLI there is beautiful symmetry: send/receive via UPDATE/SELECT are working correctly, without changing encoding.
These two lines have asymmetry in encoding handling:
c.execute("update sphinx___testapp_testmodel set attr_string=%s WHERE id = %s",
("за вдв", 1))
c.execute("select id, attr_string from sphinx___testapp_testmodel;")
mysqlclient used mysql_set_character_set after connection is made. It uses SET NAMES utf8 query.
But sphinxsearch doesn't support SET NAMES utf8. So mysql_set_character_set doesn't change connection charset and default client charset (latin1 before MySQL 8, utf8 after MySQL 8) are used.
#382 configure the charset before calling mysql_real_connect. It doesn't use SET NAMES query.
Activity
tumb1er commentedon Aug 9, 2019
Fixed with manual string converters:
This helps partially (sphinxsearch specific)
methane commentedon Aug 9, 2019
It's totally wrong solution. Don't use the converter at all.
methane commentedon Aug 9, 2019
Actually speaking, you broke your library by this commit: tumb1er/django_sphinxsearch@9519c5f
mysqlclient automatically decodes the string. But you override it so mysqlclient doesn't decode the string anymore. But a bug in mysqlclient (#343) hided your bug. Fixing #343 revealed your bug.
I hate converter. It is source of tons of bugs. It is not tested well. Overriding converter will cause surprising bugs like yours.
tumb1er commentedon Aug 10, 2019
Yes, I agree. That was an attempt to fix ascii decoding errors appeared nobody knows when and where. Most probable candidates are sphinxsearch update from 2.3.x to 3.1.x and mysqlclient bugfixes.
I tried to enable
use_unicodeflag without converter, but I have 1 single error left:Russian characters are not decoded correctly. Do you have any ideas, how to determine cause of with error (sphinxsearch vs mysqlclient usage)?
tumb1er commentedon Aug 10, 2019
Looks like it's decoding on python side:
What is the difference of using converters vs use_unicode for strings?
methane commentedon Aug 10, 2019
Have you specified charset? Until MySQL 8.0, the default connection charset was latin1.
You can override the encoding by charset="utf8mb4" option.
tumb1er commentedon Aug 10, 2019
It seems, defaults for sphinxsearch are different. Setting charset to "utf8mb4" or "utf8" does not fix decoding error.
This is fun. Russian letters are ok (it's default windows charset for russian language), but now encoding is broken :-/
tumb1er commentedon Aug 10, 2019
Interesting.
use_unicode=Truewithout converters works exactly asmethane commentedon Aug 10, 2019
It seems you are confused by Django wrappers.
Play Sphinx with bare MySQLdb and learn the behavior.
After that, read source of Django backend.
tumb1er commentedon Aug 10, 2019
Plain MySQLdb also works in confusing manner...
I'm also confused with this line in
Connection.__init__:Which encoding uses
_bytes_or_str?methane commentedon Aug 10, 2019
I expect data in your table is broken already.
Try MySQL CLI.
tumb1er commentedon Aug 10, 2019
Tried already, no errors.
I mean, in MySQL CLI there is beautiful symmetry: send/receive via UPDATE/SELECT are working correctly, without changing encoding.
These two lines have asymmetry in encoding handling:
This is strange and wrong.
methane commentedon Aug 11, 2019
I confirmed the issue. And #382 will fix it.
mysqlclient used
mysql_set_character_setafter connection is made. It usesSET NAMES utf8query.But sphinxsearch doesn't support
SET NAMES utf8. So mysql_set_character_set doesn't change connection charset and default client charset (latin1 before MySQL 8, utf8 after MySQL 8) are used.#382 configure the charset before calling
mysql_real_connect. It doesn't useSET NAMESquery.methane commentedon Aug 11, 2019
I released 1.4.4.