id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc,branch,changelog,apichanges,internalchanges 8623,env.config.save() may destroy trac.ini,Emmanuel Blot,Remy Blank,"{{{ Trac: 0.12dev-r8263 Python: 2.5.4 (r254:67916, Feb 17 2009, 20:36:34) [GCC 4.3.3] setuptools: 0.6c9 psycopg2: 2.0.9 Genshi: 0.6dev-r1052 Babel: - mod_wsgi: 2.5 Pygments: 1.0 Bitten: 0.6dev-r0 Subversion: 1.6.4 (r38063) RPC: 1.0.6 jQuery: 1.3.2 }}} If a plugin (namely: [th:CustomFieldAdminPlugin]) provides invalid data to the Configuration module, Trac raises an error ''while'' updating the configuration file. The net result is a partially written `trac.ini` which early terminates right after the last valid processed option. I know the first culprit is the plugin which should not provide invalid data to Trac, however the issue here is not a recoverable: the `trac.ini` file is simply destroyed, and it seems Trac does not attempt to keep a backup configuration file. It would be better and more realiable to: 1. create a new temporary file with the new configuration, then 1. replace the existing configuration file once the new one has been successfully created {{{ 2009-09-01 10:33:40,326 Trac[main] ERROR: Internal Server Error: Traceback (most recent call last): File ""/local/engine/trac/trac/web/main.py"", line 464, in _dispatch_request dispatcher.dispatch(req) File ""/local/engine/trac/trac/web/main.py"", line 212, in dispatch resp = chosen_handler.process_request(req) File ""/local/engine/trac/trac/admin/web_ui.py"", line 114, in process_request path_info) File ""build/bdist.linux-i686/egg/customfieldadmin/customfieldadmin.py"", line 72, in render_admin_panel cfapi.update_custom_field(self.env, cfdict, create=True) File ""build/bdist.linux-i686/egg/customfieldadmin/api.py"", line 99, in update_custom_field self.create_custom_field(env, customfield) File ""build/bdist.linux-i686/egg/customfieldadmin/api.py"", line 92, in create_custom_field env.config.save() File ""/local/engine/trac/trac/config.py"", line 198, in save val.encode('utf-8'))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128) }}} The error does not end up right here.[[br]] Once Trac has self-destroyed its own configuration file, it starts reporting a funny error: {{{ 2009-09-01 10:33:45,403 Trac[env] ERROR: Exception caught while checking for upgrade: Traceback (most recent call last): File ""/local/engine/trac/trac/env.py"", line 590, in open_environment needs_upgrade = env.needs_upgrade() File ""/local/engine/trac/trac/env.py"", line 429, in needs_upgrade db = self.get_db_cnx() File ""/local/engine/trac/trac/env.py"", line 275, in get_db_cnx return DatabaseManager(self).get_connection() File ""/local/engine/trac/trac/db/api.py"", line 88, in get_connection return self._cnx_pool.get_cnx(self.timeout or None) File ""/local/engine/trac/trac/db/pool.py"", line 176, in get_cnx return _backend.get_cnx(self._connector, self._kwargs, timeout) File ""/local/engine/trac/trac/db/pool.py"", line 109, in get_cnx cnx = connector.get_connection(**kwargs) File ""/local/engine/trac/trac/db/sqlite_backend.py"", line 127, in get_connection return SQLiteConnection(path, params, log) File ""/local/engine/trac/trac/db/sqlite_backend.py"", line 173, in __init__ raise TracError(_('Database ""%(path)s"" not found.', path=path)) TracError: Database ""/local/var/trac/projects/conax/db/trac.db"" not found. }}} I'm not sure how/why Trac wants to find a `trac.db` file, it is likely that it falls back to SQLite when it cannot find the DB connection string, but the message for the admin is hard to understand: Trac fails to connect to a DB which has never existed, because the connection string does not exist anymore in the configuration file. It would be better to report a missing connection string here. It seems that this error does not stop Trac from accessing the DB. So the final error is {{{ 2009-09-01 10:33:45,489 Trac[main] ERROR: Exception caught while post-processing request: Traceback (most recent call last): File ""/local/engine/trac/trac/web/main.py"", line 246, in dispatch self._post_process_request(req) File ""/local/engine/trac/trac/web/main.py"", line 332, in _post_process_request f.post_process_request(req, *(None,)*extra_arg_count) File ""build/bdist.linux-i686/egg/revtree/web_ui.py"", line 224, in post_process_request if req.perm.has_permission('REVTREE_VIEW'): File ""/local/engine/trac/trac/perm.py"", line 526, in has_permission return self._has_permission(action, resource) File ""/local/engine/trac/trac/perm.py"", line 540, in _has_permission check_permission(action, perm.username, resource, perm) File ""/local/engine/trac/trac/perm.py"", line 427, in check_permission perm) File ""/local/engine/trac/trac/perm.py"", line 284, in check_permission get_user_permissions(username) File ""/local/engine/trac/trac/perm.py"", line 359, in get_user_permissions for perm in self.store.get_user_permissions(username): File ""/local/engine/trac/trac/perm.py"", line 175, in get_user_permissions db = self.env.get_db_cnx() File ""/local/engine/trac/trac/env.py"", line 275, in get_db_cnx return DatabaseManager(self).get_connection() File ""/local/engine/trac/trac/db/api.py"", line 88, in get_connection return self._cnx_pool.get_cnx(self.timeout or None) File ""/local/engine/trac/trac/db/pool.py"", line 176, in get_cnx return _backend.get_cnx(self._connector, self._kwargs, timeout) File ""/local/engine/trac/trac/db/pool.py"", line 109, in get_cnx cnx = connector.get_connection(**kwargs) File ""/local/engine/trac/trac/db/sqlite_backend.py"", line 127, in get_connection return SQLiteConnection(path, params, log) File ""/local/engine/trac/trac/db/sqlite_backend.py"", line 173, in __init__ raise TracError(_('Database ""%(path)s"" not found.', path=path)) TracError: Database ""/local/var/trac/projects/conax/db/trac.db"" not found. 2009-09-01 10:33:45,489 Trac[main] WARNING: HTTPInternalError: 500 Trac Error (Database ""/local/var/trac/projects/conax/db/trac.db"" not found.) }}} ",defect,closed,highest,0.11.7,general,0.12dev,normal,fixed,config,osimons ryano@… mikael@…,,,,