Django

Code

Ticket #1356 (closed: duplicate)

Opened 3 years ago

Last modified 2 years ago

[patch] database charset and mysql backend

Reported by: little Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: Keywords: mysql charset utf8
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 1

Description

This is moved over from #1355:

2. In django.core.db.backends.mysql.DatabaseWrapper? in method cursor() When you doing

            self.connection = Database.connect(**kwargs)
        cursor = self.connection.cursor()
        if self.connection.get_server_info() >= '4.1':
            cursor.execute("SET NAMES 'utf8'")

After 'set names ..' the charset of connection was changed. But self.connection.charset property (property of MySQLdb.connection) was not changed. It is always 'Latin1' So, when i pass u"unicode national characters" into database, MySQLdb tryed to convert it into Latin1 and exception raises

To fix it, i must set .charset propery manually:

...
            self.connection = Database.connect(**kwargs)
            self.connection.charset = 'utf8'
        cursor = self.connection.cursor()
        if self.connection.get_server_info() >= '4.1':
            cursor.execute("SET NAMES 'utf8'")
...

Attachments

mysql.4_1.unicode.diff (0.8 kB) - added by Philipp Keller <philipp.keller@gmail.com> on 01/07/07 10:41:53.
test.html (40.2 kB) - added by anonymous on 01/16/07 06:12:57.

Change History

02/14/06 09:09:17 changed by hugo

  • component changed from Admin interface to Database wrapper.
  • reporter changed from hugo to little.

01/07/07 10:41:53 changed by Philipp Keller <philipp.keller@gmail.com>

  • attachment mysql.4_1.unicode.diff added.

01/07/07 10:48:09 changed by Philipp Keller <philipp.keller@gmail.com>

I ran into the same problem as reported in this ticket. My posted diff is slightly different than the proposed change. The diff is really small and really shouldn't cause any problems.

01/07/07 10:51:28 changed by Philipp Keller <philipp.keller@gmail.com>

  • owner changed from adrian to anonymous.
  • status changed from new to assigned.
  • summary changed from database charset and mysql backend to [patch] database charset and mysql backend.

01/07/07 10:52:26 changed by Philipp Keller <philipp.keller@gmail.com>

  • owner changed from anonymous to adrian.
  • status changed from assigned to new.

01/16/07 06:12:57 changed by anonymous

  • attachment test.html added.

01/17/07 23:03:08 changed by Simon G. <dev@simon.net.nz>

  • keywords set to mysql charset utf8.
  • stage changed from Unreviewed to Ready for checkin.

I've checked and this doesn't appear to conflict with #3151 ([4267]).

01/26/07 03:20:08 changed by anton@khalikov.ru

Guys, please take a look at #3370 this line:

self.connection.charset = 'utf8'

does not work in my environment (MySQL 5.0), and it only works when I pass 'charset': 'utf8' to kwargs when doing:

self.connection = Database.connect(**kwargs)

01/26/07 04:19:55 changed by Michael Radziej <mir@noris.de>

  • needs_better_patch set to 1.
  • needs_tests set to 1.
  • stage changed from Ready for checkin to Design decision needed.

We have a bit of chaos here ... Tickets #3370, #1356 and probably #952 all are about this problem, all are accepted, and #3370 and #1356 have very similar patches. I ask everybody to continue discussion in django-developers ("unicode issues in multiple tickets"), and I ask the authors of these three tickets to work together to find out how to proceed.

As long as it's not clear which path to take, I mark all bugs as "design decision needed." (I assume that the other reviews were not aware of the competing tickets.)

http://groups.google.com/group/django-developers/browse_thread/thread/4b71be8257d42faf

03/09/07 06:56:51 changed by mtredinnick

I wouldn't be too surprised to discover that #2635 fixes this particular problem and some of the others.

04/06/07 04:06:56 changed by Michael Radziej <mir@noris.de>

  • status changed from new to closed.
  • resolution set to duplicate.

duplicate of #3754 (and fixed). It's still a bug for mysql_old, but mysql_old is deprecated.


Add/Change #1356 ([patch] database charset and mysql backend)




Change Properties
Action