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
When I am using mysql collate utf8_bin on tag name field and have tag names with unicode characters such as á, django template throws DjangoUnicodeDecodeError in force_unicode(value):
'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128). You passed in <Tag: [Bad Unicode data]> (<class 'taggit.models.Tag'>)
Replacing tag name column collate utf8_bin with utf8_general_ci fixes this issue but raises a different issue with IntegrityError when trying to save tags with different casing.
I have added a fix in my fork which solves the issue in my scenario by making sure the str function always returns unicode by casting to utf8 if mysqldb returns byte string: cimani@bf26627
I would love for this fix to go into the master but I do realize that this changes forces utf8 which might not apply to all applications of this awesome plugin. I am guessing making encoding as an optional parameter passed through TaggableManager init function and applied to the underlying tag class to be used by this function would be one way around this. But I am not exactly sure how to implement this in a nice and clean way yet. If anyone has any good ideas on this, please point me to right direction :)
The text was updated successfully, but these errors were encountered:
I strongly recommend people using mysql-python to use https://pypi.python.org/pypi/mysqlclient instead. It's a fork that's well maintained and has python 3 support. Django recommends it now.
When I am using mysql collate utf8_bin on tag name field and have tag names with unicode characters such as á, django template throws DjangoUnicodeDecodeError in force_unicode(value):
'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128). You passed in <Tag: [Bad Unicode data]> (<class 'taggit.models.Tag'>)
Replacing tag name column collate utf8_bin with utf8_general_ci fixes this issue but raises a different issue with IntegrityError when trying to save tags with different casing.
I have added a fix in my fork which solves the issue in my scenario by making sure the str function always returns unicode by casting to utf8 if mysqldb returns byte string: cimani@bf26627
I would love for this fix to go into the master but I do realize that this changes forces utf8 which might not apply to all applications of this awesome plugin. I am guessing making encoding as an optional parameter passed through TaggableManager init function and applied to the underlying tag class to be used by this function would be one way around this. But I am not exactly sure how to implement this in a nice and clean way yet. If anyone has any good ideas on this, please point me to right direction :)
The text was updated successfully, but these errors were encountered: