Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12305 closed defect (fixed)

The plugin breaks CSV/TSV exports

Reported by: Phillip Leder <phillip.leder@…> 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 9 years ago by Phillip Leder <phillip.leder@…>

Installed Plugins
Name	Version	Location
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
timingandestimationplugin 	1.4.6b 	/usr/local/lib/python2.7/dist-packages/timingandestimationplugin-1.4.6b-py2.7.egg (inactive)
TracAccountManager 	0.4.3 	/usr/lib/python2.7/dist-packages (inactive)
TracCustomFieldAdmin 	0.2.12 	/usr/lib/python2.7/dist-packages
TracMasterTickets 	3.0.2 	/usr/lib/python2.7/dist-packages (inactive)

Here's the list of installed plugins, should have included it in the initial message. The Plugins marked with (inactive) are greyed out.

comment:2 Changed 9 years ago by Jun Omae

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): 
    2525    return self.render('text', None, **keys)
    2626Stream.textOf = textOf
    2727
     28
     29class 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 9 years ago by Jun Omae

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'): 
    7474    return (content.getvalue(), '%s;charset=utf-8' % mimetype)
    7575
    7676
    77 QueryModule.export_csv = new_csv_export
     77def _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
     87QueryModule.export_csv = _monkey_patch(new_csv_export, QueryModule.export_csv)
     88
    7889
    7990class TicketFormatFilter(Component):
    8091    """Filtering the streams to alter the base format of the ticket"""

comment:4 Changed 9 years ago by Russ Tyndall

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:5 Changed 9 years ago by Russ Tyndall

Resolution: fixed
Status: newclosed

In 14580:

Replace CSV filter with one that doesnt require monkey patching (or does this in a more controlled manner) v1.4.7b fix #12305

comment:6 Changed 9 years ago by Phillip Leder <phillip.leder@…>

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!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Russ Tyndall.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.