#27901 closed Bug (wontfix)
Unicode subclasses can't be saved to TextField with MySQL and Python 2
Reported by: | Dominique Barton | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.10 |
Severity: | Normal | Keywords: | mysql, unicode, error |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hi there
I use a custom model field (inherited from TextField
) which simply returns its value as an "enhanced" unicode
object.
Unfortunately, this will raise UnicodeErrors as MySQLdb apparently fails recognizing those values as unicode
. The comparision isn't very clever there ;)
MySQLdb has a use_unicode
flag, but I don't know how to implement it in Django and I think this is a serious bug.
I've prepared a whole test case right here: https://github.com/domibarton/django-mysql-unicode-error
I hope this is enough for a "proper" bug description.
Cheers
Domi
EDIT: It has NOTHING to do with my custom text field, this was just an example. Basically Django (or MySQLdb) fails when writing non-unicode
objects (but unicode
-inherited objects) values to a TextField
. Proof for that issue is right here: https://gist.github.com/domibarton/aa691342321f63f3511bb1ff53b946c7
Change History (8)
follow-up: 4 comment:1 by , 8 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:2 by , 8 years ago
comment:3 by , 8 years ago
I was in the IRC channels and they sent me here. I specifically asked them "is this really OK to file a bug" and the answer was "yes it is".
Now you tell me I've to go back?
comment:4 by , 8 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
Replying to Tim Graham:
From what you provided so far, it looks like you're asking for help debugging your custom field.
No I don't need help with debugging my custom field as my custom field is not the problem! As I described before, IT IS A BUG and therefore I think this ticket is quite valid!
Let's keep it simple and ignore the fact that I'm trying to make a custom model field. Use a stock TextField
, write a value to it and then save the model. Now do the same, but use a custom unicode
class for the value. Something like that:
https://gist.github.com/domibarton/aa691342321f63f3511bb1ff53b946c7
comment:5 by , 8 years ago
Description: | modified (diff) |
---|---|
Summary: | Problem with Django & MySQL & model fields returning custom unicode classes → Problem with Django models & MySQL & custom unicode classes |
comment:6 by , 8 years ago
Additional info:
Switching from mysql-python
to mysqlcient
didn't help.
However, switching from python2 to python3 solves the issue.
This might be because in py3 everything is unicode by default (vs. byte strings in py2) and the "default" type is unicode.
I'll try to migrate my project to py3 and the bug is gone. Unfortunately it still exists with py2.
follow-up: 8 comment:7 by , 8 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Summary: | Problem with Django models & MySQL & custom unicode classes → Unicode subclasses can't be saved to TextField with MySQL and Python 2 |
Even if Django is at fault (it's still not clear to me if that's the case), the time for fixing issues that only affect Python 2 has passed since Django's master branch only supports Python 3.
comment:8 by , 8 years ago
Replying to Tim Graham:
Even if Django is at fault (it's still not clear to me if that's the case), the time for fixing issues that only affect Python 2 has passed since Django's master branch only supports Python 3.
Didn't know that. OK, I'll try to move everything to py3.
In this case, you need to explain why Django is at fault and ideally provide a patch that fixes the issue. From what you provided so far, it looks like you're asking for help debugging your custom field. For ways to get help with that, see TicketClosingReasons/UseSupportChannels.