Edgewall Software
Modify

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#10897 closed defect (duplicate)

initenv with non-utf8 mysql database should give a more helpful error

Reported by: Ethan Jucovy <ethan.jucovy@…> Owned by:
Priority: low Milestone:
Component: database backend Version:
Severity: normal Keywords: patch mysql
Cc: felix.schwarz@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

If I create a MySQL database for a new Trac environment but forget to create the database with the UTF8 character set, then trac-admin /path/to/env initenv projectname mysql://connectionstring fails with a mysterious error:

Creating and Initializing Project
Initenv for '/path/to/env' failed. 
Failed to create environment.
unsupported operand type(s) for /: 'int' and 'NoneType'
Traceback (most recent call last):
  File "trac/trac/admin/console.py", line 455, in do_initenv
    options=options)
  File "trac/trac/core.py", line 124, in __call__
    self.__init__(*args, **kwargs)
  File "trac/trac/env.py", line 281, in __init__
    self.create(options)
  File "trac/trac/env.py", line 584, in create
    DatabaseManager(self).init_db()
  File "trac/trac/db/api.py", line 249, in init_db
    connector.init_db(**args)
  File "trac/trac/db/mysql_backend.py", line 119, in init_db
    for stmt in self.to_sql(table, utf8_size=utf8_size):
  File "trac/trac/db/mysql_backend.py", line 168, in to_sql
    utf8_size=utf8_size))
  File "trac/trac/db/mysql_backend.py", line 132, in _collist
    limit_col = 767 / utf8_size
TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'

This is not a very Google-friendly error. It would be nice if Trac could detect the problem before this TypeError occurs, and raise an error message that explains what the user did wrong.

Attachments (1)

10897_detect_no_utf8.diff (834 bytes ) - added by Ethan Jucovy <ethan.jucovy@…> 11 years ago.
patch to raise a more user-friendly error if mysql db is not using utf8 charset

Download all attachments as: .zip

Change History (7)

by Ethan Jucovy <ethan.jucovy@…>, 11 years ago

Attachment: 10897_detect_no_utf8.diff added

patch to raise a more user-friendly error if mysql db is not using utf8 charset

comment:1 by Christian Boos, 11 years ago

Milestone: next-stable-1.0.x

Good idea!

However, no need to put the link in full in the error message.

Try something like:

mysql_utf8 = tag.a(_("How to set up MySQL correctly...", 
                   href='http://trac.edgewall.org/wiki/...')
tag_("... See %(mysql_utf8)s ...", mysql_utf8=mysql_utf8)

(see e.g. source:tags/trac-0.12/trac/versioncontrol/web_ui/util.py@:64-71#L64)

comment:2 by Jun Omae, 11 years ago

Related to comment:16:ticket:8089 and T8089 MySQL charset collation check on create DB.patch.

I think the message of TracError should be plain text. Because initenv command normally is executed from user's terminal.

comment:3 by Felix Schwarz, 11 years ago

Cc: felix.schwarz@… added

comment:4 by anonymous, 11 years ago

Keywords: mysql added

comment:5 by Jun Omae, 10 years ago

Milestone: next-stable-1.0.x1.0.2
Resolution: duplicate
Status: newclosed

After [12148], Trac verifies the charset and collation. See #10993.

Trac [/var/trac/1.0-test]> initenv title mysql://tracuser:password@localhost/trac
Creating and Initializing Project
Initenv for '/var/trac/1.0-test' failed.
Failed to create environment.
The charset and collation of database are 'latin1' and 'latin1_swedish_ci'. The database must be created with one of (('utf8', 'utf8_bin'), ('utf8mb4', 'utf8mb4_bin')).
Traceback (most recent call last):
  File "trac/admin/console.py", line 456, in do_initenv
    options=options)
...

comment:6 by Peter Suter, 10 years ago

Milestone: 1.0.2

Modify Ticket

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