Edgewall Software
Modify

Opened 11 years ago

Closed 11 years ago

#11313 closed defect (fixed)

mysql_backend with parameters raises TypeError on initenv

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.0.2
Component: database backend Version: 1.0-stable
Severity: normal Keywords: mysql
Cc: Branch:
Release Notes:

Fix errors if mysql: dburi has parameters on initenv

API Changes:
Internal Changes:

Description

When executing initenv command with mysql backend and init_command parameter, it raises TypeError: Connect() keywords must be strings.

Parameters for mysql backend are introduced in [10407], #5120.

$ python trac/admin/console.py /var/trac/1.0-test
Welcome to trac-admin 1.0.2dev
Interactive Trac administration console.
Copyright (C) 2003-2013 Edgewall Software

Type:  '?' or 'help' for help on commands.

Trac [/var/trac/1.0-test]> initenv "Trac 1.0-stable w/ MySQL" "mysql://tracuser:password@localhost/trac_1_0_test?init_command=SET storage_engine%3dMyISAM"
Creating and Initializing Project
Initenv for '/var/trac/1.0-test' failed.
Failed to create environment.
Connect() keywords must be strings
Traceback (most recent call last):
  File "trac/admin/console.py", line 456, in do_initenv
    options=options)
  File "/home/jun66j5/src/trac/edgewall/git/trac/core.py", line 124, in __call__
    self.__init__(*args, **kwargs)
  File "/home/jun66j5/src/trac/edgewall/git/trac/env.py", line 280, in __init__
    self.create(options)
  File "/home/jun66j5/src/trac/edgewall/git/trac/env.py", line 580, in create
    DatabaseManager(self).init_db()
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/api.py", line 251, in init_db
    connector.init_db(**args)
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/mysql_backend.py", line 111, in init_db
    params)
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/mysql_backend.py", line 92, in get_connection
    cnx = MySQLConnection(path, log, user, password, host, port, params)
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/mysql_backend.py", line 275, in __init__
    port=port, charset='utf8', **opts)
TypeError: Connect() keywords must be strings
make: *** [console] Error 1
  • trac/db/mysql_backend.py

    diff --git a/trac/db/mysql_backend.py b/trac/db/mysql_backend.py
    index cea17b2..b2537c6 100644
    a b class MySQLConnection(ConnectionWrapper):  
    263263            port = 3306
    264264        opts = {}
    265265        for name, value in params.iteritems():
     266            name = name.encode('utf-8')
    266267            if name in ('init_command', 'read_default_file',
    267268                        'read_default_group', 'unix_socket'):
    268269                opts[name] = value

Attachments (0)

Change History (2)

comment:1 by Jun Omae, 11 years ago

Owner: set to Jun Omae
Status: newassigned

Also, I've found another thing. We should convert the file paths in unix_socket and read_default_file to filesystem encoding. If passing a path as unicode, those are converted with default encoding.

Trac [/var/trac/1.0-test]> initenv "my project" "mysql://tracuser:password@localhost/trac_1_0_test?read_default_file=/étc/my.cnf"
Creating and Initializing Project
Initenv for '/var/trac/1.0-test' failed.
Failed to create environment.
'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)
Traceback (most recent call last):
  File "trac/admin/console.py", line 456, in do_initenv
    options=options)
  File "/home/jun66j5/src/trac/edgewall/git/trac/core.py", line 124, in __call__
    self.__init__(*args, **kwargs)
  File "/home/jun66j5/src/trac/edgewall/git/trac/env.py", line 280, in __init__
    self.create(options)
  File "/home/jun66j5/src/trac/edgewall/git/trac/env.py", line 580, in create
    DatabaseManager(self).init_db()
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/api.py", line 251, in init_db
    connector.init_db(**args)
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/mysql_backend.py", line 114, in init_db
    params)
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/mysql_backend.py", line 95, in get_connection
    cnx = MySQLConnection(path, log, user, password, host, port, params)
  File "/home/jun66j5/src/trac/edgewall/git/trac/db/mysql_backend.py", line 280, in __init__
    port=port, charset='utf8', **opts)
  File "/usr/lib/python2.5/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)

Proposed changes can be found in [103926c7/jomae.git].

comment:2 by Jun Omae, 11 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

And another thing, raising UnicodeEncodeError if init_command with unicode.

Trac [/var/trac/1.0-test]> initenv "my project" "mysql://tracuser:password@localhost/trac_1_0_test?init_command=SET storage_engine=InnoDB -- é (U+009E)"
...
  File "/usr/lib/python2.5/site-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 29: ordinal not in range(128)

The proposed fix can be found in [139420d06/jomae.git].

Those changes have been pushed in [12113] and merged into trunk in [12114].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae 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.