Edgewall Software
Modify

Opened 18 years ago

Closed 17 years ago

Last modified 11 years ago

#3267 closed defect (wontfix)

mysql charset support for older python-mysqldb versions

Reported by: Andres Salomon Owned by: Matthew Good
Priority: high Milestone:
Component: general Version: 0.10.4
Severity: normal Keywords: mysql
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Currently, mysql support in Trac requires mysql 4.1 and python-mysqldb 1.2.1. I thought this was okay, but as it turns out python-mysqldb is pretty new (not even in the recently released Ubuntu Dapper). If trac is used w/ an older mysqldb module, it breaks immediately due to a lack of charset support.

Attachments (1)

trac_mysql.patch (2.2 KB ) - added by Andres Salomon 18 years ago.
this is against r3390

Download all attachments as: .zip

Change History (13)

by Andres Salomon, 18 years ago

Attachment: trac_mysql.patch added

this is against r3390

comment:1 by Andres Salomon, 18 years ago

The attached patch works around the lack of 'charset' option in MySQLdb.connect(). It checks the version of python-mysqldb; if it turns out to be lower than 1.2.1, than it calls MySQLdb.connect() without the 'charset' option, and manually sets the charset via MySQL's 'SET NAMES'.

Note that without setting the charset, mysql support breaks horrible; the unicode stuff that was merged requires this.

comment:2 by Manuzhai, 18 years ago

Shouldn't it also do SET CHARACTER SET utf8?

comment:3 by Jonas Borgström, 18 years ago

Resolution: fixed
Status: newclosed

Thanks,

I've tested this patch with mysql5 and as far as I can tell it works and it's not necessary to do "SET CHARACTER SET utf8".

Applied in r3453.

comment:4 by jon@…, 18 years ago

Resolution: fixed
Status: closedreopened

When doing

trac-admin /path/to/trac-env initenv

I'm getting

Failed to create environment. 'use_unicode' is an invalid keyword argument for this function.

I'm using Redhat Enterprise Linux, 4.1 with the following (what I believe to be relevant) RPMs installed:

  • mysql-4.1.12-3.RHEL4.1
  • mysqlclient10-3.23.58-4.RHEL4.1
  • libdbi-dbd-mysql-0.6.5-10.RHEL4.1
  • MySQL-python-1.0.0-1.RHEL4.1

I've done some tweaks to try and get it working, but if I remove "use_unicode=True" from trac/db/mysql_backend.py (line 143), I get

/usr/share/trac/wiki-default/TracInstall => TracInstall

Failed to initialize environment. 'latin-1' codec can't encode character u'\u201c' in position 9798: ordinal not in range(256)

I'm happy to provide any further details, but this is my first shot at anything to do with python, so I'm a little green!

in reply to:  4 comment:5 by Matthew Good, 18 years ago

Owner: changed from Jonas Borgström to Matthew Good
Status: reopenednew

Replying to jon@spriggs.org.uk:

  • MySQL-python-1.0.0-1.RHEL4.1

It appears that this patch only adds support for pre-release versions of MySQLdb 1.2.1 (c5 or earlier). The "charset" option was added in 1.2.1c6, but MySQLdb 1.1 or earlier did not have the "use_unicode" option.

comment:6 by Christian Boos, 18 years ago

Shouldn't we fix this for 0.10.1, along with all the other MySQL related tickets?

comment:7 by Matthew Good, 18 years ago

Milestone: 0.10.3
Version: devel0.10.2

comment:8 by Christian Boos, 18 years ago

Milestone: 0.10.4
Resolution: wontfix
Status: newclosed

Well, I think that given the trouble we already have supporting the recent versions of MySQL, there's no point in adding more trouble for trying to support older releases.

The MySqlDb page tries to gather the requirements for running Trac with MySQL. There's already a strict requirement on the charsets that have to be used for the database, though the requirement on the MySQLdb python bindings is less clear, as 1.2.1 doesn't seem to work in all cases.

comment:9 by JensDiemer, 18 years ago

MySQLdb and Version-String :-/

v1.2.1_p2 has kwarg "charset" v1.2.1g2 has kwarg "use_unicode"

So i think the Patch http://trac.edgewall.org/attachment/ticket/3267/trac_mysql.patch doesn't work correctly. Isn't it?

I used this solution: I try it with "charset", if it does not go, then i use "use_unicode".

comment:10 by malaguna@…, 17 years ago

Resolution: wontfix
Status: closedreopened
Version: 0.10.20.10.4

I have just installed trac 0.10.4 in a fedora 7 with mysql 5.0.37 and MySQL-python-1.2.2, and still get this error.

I also have cheked that patch is inlcuded in the source

in reply to:  10 comment:11 by Christian Boos, 17 years ago

Keywords: mysql added
Resolution: wontfix
Status: reopenedclosed

Replying to malaguna@gmail.com:

I have just installed trac 0.10.4 in a fedora 7 with mysql 5.0.37 and MySQL-python-1.2.2, and still get this error.

Please don't mix up everything, this ticket is about supporting old MySQL versions (< 4.1) and we would like to keep a plain clear wontfix resolution for this one.

There are (unfortunately) plenty other tickets for MySqlDb (check in the Known issues section in that page) where you can add a me too comment… But before doing that, check the requirements (also listed in the MySqlDb page) that the database should be an UTF-8 one.

in reply to:  10 comment:12 by anonymous, 11 years ago

Replying to malaguna@…:

I have just installed trac 0.10.4 in a fedora 7 with mysql 5.0.37 and MySQL-python-1.2.2, and still get this error.

I also have cheked that patch is inlcuded in the source

6 years ago, if it helps and still need you :) i have trac 0.10.4 in centos 5 with mysql 5.5

resolved problem with "Failed to initialize environment. 'latin-1' codec can't encode character" next:

  1. in trac-admin changed charset to utf-8
  2. in trac/db/mysql_backend.py comment out:
# if (self._mysqldb_gt_or_eq((1, 2, 1))):
            cnx = MySQLdb.connect(db=path, user=user, passwd=password, 
                                  host=host, port=port, charset='utf8') 
# else:
#            cnx = MySQLdb.connect(db=path, user=user, passwd=password,
#                                  host=host, port=port, use_unicode=True)
# self._set_character_set(cnx, 'utf8') 
Last edited 11 years ago by Ryan J Ollos (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Matthew Good.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Matthew Good to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.