#10897 closed defect (duplicate)
initenv with non-utf8 mysql database should give a more helpful error
| Reported by: | 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)
Change History (7)
by , 13 years ago
| Attachment: | 10897_detect_no_utf8.diff added |
|---|
comment:1 by , 13 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 , 13 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 , 12 years ago
| Cc: | added |
|---|
comment:4 by , 12 years ago
| Keywords: | mysql added |
|---|
comment:5 by , 12 years ago
| Milestone: | next-stable-1.0.x → 1.0.2 |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
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 , 12 years ago
| Milestone: | 1.0.2 |
|---|



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