#11846 closed enhancement (fixed)
Prevent invalid file in Environment plugins directory from disabling Trac instance
| Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2.3 |
| Component: | general | Version: | |
| Severity: | normal | Keywords: | plugins |
| Cc: | Branch: | ||
| Release Notes: |
A module in the |
||
| API Changes: | |||
| Internal Changes: | |||
Description (last modified by )
imp.load_source can raise a SystemExit exception when there is an invalid file in the Environment's plugins directory. A common scenario seems to be that the user will select setup.py with the plugin installation file picker on the Plugins admin panel.
The patch might be as simple as (needs more testing):
-
trac/loader.py
diff --git a/trac/loader.py b/trac/loader.py index df65356..444e78d 100644
a b def load_py_files(): 87 87 env.log.debug('Loading file plugin %s from %s', 88 88 plugin_name, plugin_file) 89 89 if plugin_name not in sys.modules: 90 module = imp.load_source(plugin_name, plugin_file) 90 try: 91 imp.load_source(plugin_name, plugin_file) 92 except SystemExit, e: 93 env.log.warn("Can't load file plugin %s: %s", 94 plugin_file, exception_to_unicode(e)) 91 95 if path == auto_enable: 92 96 _enable_plugin(env, plugin_name) 93 97 except Exception, e:
The issue has come up a few times recently:
Attachments (0)
Change History (12)
comment:1 by , 11 years ago
| Reporter: | changed from to |
|---|
comment:2 by , 11 years ago
comment:4 by , 10 years ago
| Milestone: | next-stable-1.0.x → next-major-releases |
|---|
comment:5 by , 10 years ago
| Description: | modified (diff) |
|---|
comment:6 by , 10 years ago
Good idea. Another idea in plugins is to invoke setup() only when run as a script, e.g. th:source:tracdragdropplugin/0.12/setup.py@14282.
comment:7 by , 10 years ago
| Description: | modified (diff) |
|---|
comment:8 by , 9 years ago
| Description: | modified (diff) |
|---|
comment:10 by , 8 years ago
| Milestone: | next-major-releases → 1.2.3 |
|---|---|
| Owner: | set to |
| Status: | new → assigned |
SystemExit is not currently trapped because it's not derived from Exception, see exception hierarchy. Therefore, I propose to commit the following simple change:
-
trac/loader.py
diff --git a/trac/loader.py b/trac/loader.py index 5fe0e3cec..7608031c6 100644
a b def load_py_files(): 92 92 except (ImportError, VersionConflict) as e: 93 93 env.log.error('Skipping "%s": %s', plugin_name, 94 94 exception_to_unicode(e)) 95 except Exceptionas e:95 except (Exception, SystemExit) as e: 96 96 env.log.error( 97 97 "Failed to load plugin from %s: %s", plugin_file, 98 98 exception_to_unicode(e, traceback=True))
comment:12 by , 8 years ago
| Release Notes: | modified (diff) |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |



Here's a relevant TODO tags/trac-1.0.2/trac/admin/web_ui.py@:500#L466. Validating the upload sounds like a good idea in addition to protecting against an invalid file in the environment
pluginsdirectory.