#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)
Change History (13)
by , 19 years ago
Attachment: | trac_mysql.patch added |
---|
comment:1 by , 19 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:3 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.
follow-up: 5 comment:4 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
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!
comment:5 by , 18 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
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 , 18 years ago
Shouldn't we fix this for 0.10.1, along with all the other MySQL related tickets?
comment:7 by , 18 years ago
Milestone: | → 0.10.3 |
---|---|
Version: | devel → 0.10.2 |
comment:8 by , 18 years ago
Milestone: | 0.10.4 |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
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 , 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".
follow-ups: 11 12 comment:10 by , 17 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
Version: | 0.10.2 → 0.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
comment:11 by , 17 years ago
Keywords: | mysql added |
---|---|
Resolution: | → wontfix |
Status: | reopened → closed |
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.
comment:12 by , 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:
- in trac-admin changed charset to utf-8
- 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')
this is against r3390