Modify

Opened 6 years ago

Closed 6 weeks ago

#9872 closed defect (fixed)

no syntax highlighting when plugin is enabled

Reported by: asix Owned by: Ryan J Ollos
Priority: normal Component: TracKeywordsPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

Note: System information and relevant plugin information follows the error information.

Problem: Syntax highlighting does not work when TracKeywordsPlugin is enabled. If I disable the keywords plugin, syntax highlighting works as expected.

Also, an error is thrown when trying to change the syntax highting preferences.

Click on Preferences, then Syntax Highlighting tab, and the following error is thrown:

[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x] mod_wsgi (pid=9470): Exception occurred processing WSGI script '/var/www/trac/cgi-bin/trac.wsgi'.,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x] Traceback (most recent call last):,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/var/www/trac/cgi-bin/trac.wsgi", line 33, in application,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     return dispatch_request(environ, start_request),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/Trac-0.12.3-py2.6.egg/trac/web/main.py", line 490, in dispatch_request,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     return _dispatch_request(req, env, env_error),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/Trac-0.12.3-py2.6.egg/trac/web/main.py", line 566, in _dispatch_request,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     send_internal_error(env, req, sys.exc_info()),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/Trac-0.12.3-py2.6.egg/trac/web/main.py", line 660, in send_internal_error,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     req.send_error(exc_info, status=500, env=env, data=data),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/Trac-0.12.3-py2.6.egg/trac/web/api.py", line 463, in send_error,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     exc_info),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/Trac-0.12.3-py2.6.egg/trac/web/main.py", line 522, in _dispatch_request,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     dispatcher.dispatch(req),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/Trac-0.12.3-py2.6.egg/trac/web/main.py", line 269, in dispatch,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     self._post_process_request(req),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/Trac-0.12.3-py2.6.egg/trac/web/main.py", line 365, in _post_process_request,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     f.post_process_request(req, *(None,)*extra_arg_count),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]   File "/usr/local/lib/python2.6/dist-packages/TracKeywordsPlugin-0.2-py2.6.egg/trackeywords/web_ui.py", line 83, in post_process_request,
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x]     data['keywords'] = self._get_keywords(),
[Thu Mar 01 13:08:59 2012] [error] [client x.x.x.x] TypeError: 'NoneType' object does not support item assignment,

System Information

Trac 0.12.3
Docutils 0.6
Genshi 0.6
Mercurial 2.1
mod_wsgi 2.8 (WSGIProcessGroup WSGIApplicationGroup %{GLOBAL})
Pygments 1.4
pysqlite 2.4.1
Python 2.6.5 (r265:79063, Apr 16 2010, 13:28:26) [GCC 4.4.3]
setuptools 0.6
SQLite 3.6.22
Subversion 1.6.6 (r40053)
jQuery:1.4.4

Installed Plugins

AutocompleteUsers 0.4.2-r10974 /usr/local/lib/python2.6/dist-packages/AutocompleteUsers-0.4.2_r10974-py2.6.egg
ExtLinkRewriter 0.5 /usr/local/lib/python2.6/dist-packages/ExtLinkRewriter-0.5-py2.6.egg
TracCustomFieldAdmin 0.2.8-r11278 /usr/local/lib/python2.6/dist-packages/TracCustomFieldAdmin-0.2.8_r11278-py2.6.egg
TracKeywordsPlugin 0.2 /usr/local/lib/python2.6/dist-packages/TracKeywordsPlugin-0.2-py2.6.egg
TracMasterTickets 3.0.2 /usr/local/lib/python2.6/dist-packages/TracMasterTickets-3.0.2-py2.6.egg
TracMercurial 0.12.0.29dev-r10936 /usr/local/lib/python2.6/dist-packages/TracMercurial-0.12.0.29dev_r10936-py2.6.egg
TracSubcomponents 1.1.2 /usr/local/lib/python2.6/dist-packages/TracSubcomponents-1.1.2-py2.6.egg
TracWatchlistPlugin 0.5 /usr/local/lib/python2.6/dist-packages/TracWatchlistPlugin-0.5-py2.6.egg
TracWikiPrintPlugin 1.9.2 /usr/local/lib/python2.6/dist-packages/TracWikiPrintPlugin-1.9.2-py2.6.egg

Attachments (0)

Change History (11)

comment:1 Changed 6 years ago by asix

FYI. Same error traceback thrown when browsing source.

comment:2 Changed 5 years ago by Steffen Hoffmann

I can imagine root cause and possible cure:

This plugin's !IRequestFilter method post_process_request extends the data dict for each request unconditionally. There are certainly a lot of requests, that have unexpected data dict content, or None at all, hence the error. I've never seen this before, and code should just be more specific about what requests to react upon, like so:

    def post_process_request(self, req, template, data, content_type):
        if template in ('ticket.html', 'wiki_edit.html'):
            data['keywords'] = self._get_keywords()
        return (template, data, content_type)

I bet this will instantly fix the issue. Anyone able to test this easily? I don't use this plugin myself as well.

comment:3 Changed 5 years ago by Steffen Hoffmann

Side-note: _get_keywords can hardly get different data without changing trac.ini, that would trigger a reload anyway. If/as soon as the plugin used separate file or wiki space for keyword storage, like was proposed in the TODO, then it could make sense to keep it that way. Or at least re-parse external source(s), for text-file still per request. For wiki pages since Trac 0.12 there is an IWikiChangeListener extension point to allow a more resource conscientious way to re-evaluate only on source change.

So I think this method don't need to be called on each request, but could the list could be prepared once (on class initialization) and get just referenced later on as self.keywords, right?

Of course all that might be overkill for just a few keywords, but I mention it for completeness and encouraging discussion about best-practice. Feel free to disagree or disregard as irrelevant.

comment:4 in reply to:  2 Changed 5 years ago by Ryan J Ollos

Status: newassigned

I can reproduce the traceback, but not the syntax highlighting issue.

comment:5 Changed 5 years ago by Ryan J Ollos

(In [11769]) Refs #9872:

  • FIX: Only add to data dictionary if the request is for rendering a page in the ticket or wiki realm.
  • Call _get_keywords on initialization and cache the data.
  • Minor style and formatting changes.
  • Deleted obsolete ClearSilver template.
  • Added setup.cfg and set version to 0.3dev.

Thanks to hasienda for the excellent suggestions and guidance.

comment:6 Changed 5 years ago by asix

Hi. Just tried the "fix" and it looks good. Errors gone, and syntax highlighting is working fine. However, it was not parsing the [keywords] section in trac.ini. That is, I only got the default ("patch", "easy"), since section returned was always empty.

So, FWIW, I changed the keyword parsing line as follows and it works now.

--- web_ui.py.orig      2012-07-25 13:43:01.576275692 -0600
+++ web_ui.py.new       2012-07-25 13:42:49.672275608 -0600
@@ -92,7 +92,7 @@
             render_template(req, 'keywords.html', data, 'MarkupTemplate', True)
 
     def _get_keywords(self):
-        section = self.env.config.get('keywords', None)
+        section = self.env.config['keywords']
         if section:
             keywords = []
             for keyword in section:

comment:7 in reply to:  6 Changed 5 years ago by Ryan J Ollos

Replying to asix:

So, FWIW, I changed the keyword parsing line as follows and it works now.

Thanks, I'll take a look now. I was being lazy and hadn't tested that.

comment:8 Changed 5 years ago by Ryan J Ollos

(In [11788]) Refs #9872, #8799: Fixed defect introduced in [11771]: keywords would not be parsed from the keywords section in trac.ini. Thanks to asix for testing and reporting this.

comment:9 Changed 4 years ago by Ryan J Ollos

Status: assignednew

comment:10 Changed 6 weeks ago by c.feige@…

I have tested this plugin (TracKeywordsPlugin 0.3dev-r0 / revision r16858) with TRAC 1.0.4 and can confirm that the syntax highlighting works fine. No problem here, anymore.

Thanks
Clemens

comment:11 Changed 6 weeks ago by Ryan J Ollos

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.

Add Comment


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

 
Note: See TracTickets for help on using tickets.