#12305 closed defect (fixed)
The plugin breaks CSV/TSV exports
Reported by: | Owned by: | Russ Tyndall | |
---|---|---|---|
Priority: | normal | Component: | TimingAndEstimationPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 1.0 |
Description
After fixing #12173 (which works fine so far), another error occured - which the users didn't report up unti now. As soon as the TimingAndEstimation-plugin is loaded into trac the export as comma/tab seperated table breaks for custom queries. It is easily reproducible, for me at least, and gives the following error/stacktrace;
Oops… Trac detected an internal error: NameError: global name 'web_context' is not defined This is probably a local installation issue. Found a bug in Trac? If you think this should work and you can reproduce the problem, you should consider creating a bug report. Note that the TracCustomFieldAdmin plugin seems to be involved. Please report this issue to the plugin maintainer. Before you do that, though, please first try searching for similar issues, as it is quite likely that this problem has been reported before. For questions about installation and configuration of Trac or its plugins, please try the mailing list instead of creating a ticket. Otherwise, please a new bug report describing the problem and explain how to reproduce it. Python Traceback Most recent call last: File "/usr/lib/python2.7/dist-packages/trac/web/main.py", line 512, in _dispatch_request File "/usr/lib/python2.7/dist-packages/trac/web/main.py", line 221, in dispatch File "/usr/lib/python2.7/dist-packages/trac/ticket/query.py", line 979, in process_request File "/usr/lib/python2.7/dist-packages/trac/mimeview/api.py", line 1022, in send_converted File "/usr/lib/python2.7/dist-packages/trac/mimeview/api.py", line 697, in convert_content File "/usr/lib/python2.7/dist-packages/trac/ticket/query.py", line 875, in convert_content File "build/bdist.linux-x86_64/egg/timingandestimationplugin/tande_filters.py", line 58, in new_csv_export System Information: User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.6.0 Trac 1.0.2 Babel 1.3 CustomFieldAdmin 0.2.6 Docutils 0.12 Genshi 0.7 (with speedups) mod_python 3.3.1 psycopg2 2.5.4 Pygments 2.0.1 Python 2.7.9 (default, Mar 1 2015, 13:01:26) [GCC 4.9.2] pytz 2012c setuptools 5.5.1 Subversion 1.8.10 (r1615264) jQuery 1.7.2 jQuery UI 1.10.1 jQuery Timepicker 1.2 Enabled Plugins: AutocompleteUsers 0.4.2dev-r13962 /usr/local/lib/python2.7/dist-packages/AutocompleteUsers-0.4.2dev_r13962-py2.7.egg DefaultCc 0.3dev-r13747 /usr/local/lib/python2.7/dist-packages/DefaultCc-0.3dev_r13747-py2.7.egg RoadmapHours 0.5 /usr/local/lib/python2.7/dist-packages/RoadmapHours-0.5-py2.7.egg TracCustomFieldAdmin 0.2.6 /usr/lib/python2.7/dist-packages
As you can see it doesn't show up as enabled. In the "About Trac" screen it is listed as an Installed Plugin but it is greyed out (it is installed as a local plugin for another Trac, but I guess the plugin management of Trac itself might be the problem in this case). As far as I can tell this problem only occurs if someone else is currently working with the TimingAndEstimation plugin.
Do you think you can do anything about that or should I try to file a bug with Trac?
Best Regards, Phillip Leder
Attachments (0)
Change History (6)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
I consider that the plugin should use IContentConverter rather than monkey patch to customize csv/tsv export for query. Don't use monkey patch.
-
timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/tande_filters.py
diff --git a/timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/tande_filters.py b/timingandestimation index c194dce..96d2f67 100644
a b def textOf(self, **keys): 25 25 return self.render('text', None, **keys) 26 26 Stream.textOf = textOf 27 27 28 29 class TandEFilteredQueryConversions(Component): 30 31 implements(IContentConverter) 32 33 # IContentConverter methods 34 35 def get_supported_conversions(self): 36 yield ('csv', _('Comma-delimited Text'), 'csv', 37 'trac.ticket.Query', 'text/csv', 9) # higher than QueryModule 38 yield ('tab', _('Tab-delimited Text'), 'tsv', 39 'trac.ticket.Query', 'text/tab-separated-values', 9) 40 41 def convert_content(self, req, mimetype, query, key): 42 if key == 'csv': 43 return self._export_csv(req, query, mimetype='text/csv') 44 elif key == 'tab': 45 return self._export_csv(req, query, '\t', 46 mimetype='text/tab-separated-values') 47 48 # Internal methods 49 50 def _export_csv(self, req, query, sep=',', mimetype='text/plain'): 51 # Put your new_csv_export here 52 # ... 53 54
comment:3 Changed 10 years ago by
If monkey patch has to be needed, the original method should be called when the plugin is disabled.
-
timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/tande_filters.py
diff --git a/timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/tande_filters.py b/timingandestimation index c194dce..b42775a 100644
a b def new_csv_export(self, req, query, sep=',', mimetype='text/plain'): 74 74 return (content.getvalue(), '%s;charset=utf-8' % mimetype) 75 75 76 76 77 QueryModule.export_csv = new_csv_export 77 def _monkey_patch(new_fn, orig_fn): 78 def fn(self, *args, **kwargs): 79 from timingandestimationplugin.api import TimeTrackingSetupParticipant 80 if self.env.is_component_enabled(TimeTrackingSetupParticipant): 81 return new_fn(self, *args, **kwargs) # this plugin is enabled 82 else: 83 return orig_fn(self, *args, **kwargs) # this plugin is disabled 84 return fn 85 86 87 QueryModule.export_csv = _monkey_patch(new_csv_export, QueryModule.export_csv) 88 78 89 79 90 class TicketFormatFilter(Component): 80 91 """Filtering the streams to alter the base format of the ticket"""
comment:4 Changed 9 years ago by
reply to: jun66j5
Thanks for the spot on advice. I didn't know about the IContentConverter
interface. If it works, I find it much preferable to the (incorrect) monkey patch.
I will work to apply a patch soon. I personally don't use this branch of the plugin, so I rely on user reports for finding bugs. Thanks Phillip Leder!
Cheers
comment:6 Changed 9 years ago by
I just got around to try it and as far as I can tell it works now. I once again told my users to report everything unusual, but let's hope that this is it for now :)
Thank you for the plugin and all the work you put into it!
Here's the list of installed plugins, should have included it in the initial message. The Plugins marked with
(inactive)
are greyed out.