Modify

Opened 10 months ago

Last modified 10 months ago

#14273 new defect

Plugin conflicting with trac-spamfilter plugin

Reported by: Oleksij Owned by: Cinc-th
Priority: normal Component: MarkdownMacro
Severity: normal Keywords:
Cc: Trac Release: 1.6

Description

First of all, thank you for your MarkDown macro plugin - I found it very useful. However, I found one small issue. I do have spam filter plugin installed and when i am clicking on Monitoring in admin menu (/admin/spamfilter/monitor URL) i am getting error:

Trac detected an internal error:

AttributeError: 'int' object has no attribute 'name'

And python traceback points to the macro:

Python Traceback
Most recent call last:

    File "/usr/local/lib/python3.9/site-packages/trac/web/main.py", line 609 , in dispatch_request
    File "/usr/local/lib/python3.9/site-packages/trac/web/main.py", line 301 , in dispatch
    File "/usr/local/lib/python3.9/site-packages/trac/web/main.py", line 250 , in dispatch
    File "/usr/local/lib/python3.9/site-packages/trac/web/main.py", line 469 , in _post_process_request
    File "/usr/local/lib/python3.9/site-packages/tracmarkdown/macro.py", line 153 , in post_process_request 

Not sure why only that page is impacted, however, i was able to fix it with that patch:

  • tracmarkdown/macro.py

     
    148148        def wiki_to_html(self, context, wikidom, escape_newlines=None):
    149149            return Markup(format_to_markdown(self, context, wikidom))
    150150
    151         if template and data and 'page' in data:
     151        if template and data and 'page' in data and hasattr(data, 'name'):
    152152            # We only handle wiki pages
    153153            path = data['page'].name.split('/')
    154154            if path[0] in self.root_pages:

I am using Trac 1.6, trac-macro is r18423, and spamfilter is r17763

Attachments (0)

Change History (1)

comment:1 Changed 10 months ago by Jun Omae

I think the patch stops markdown formatting on wiki pages (data variable is a dict instance and doesn't have name attribute).

Instead, try the following patch:

  • markdownmacro/trunk/tracmarkdown/macro.py

    diff --git a/markdownmacro/trunk/tracmarkdown/macro.py b/markdownmacro/trunk/tracmarkdown/macro.py
    index 53a7a283a..d15d6b57a 100644
    a b from trac.util.html import Markup, html as tag, TracHTMLSanitizer 
    4545from trac.web.api import IRequestFilter, IRequestHandler
    4646from trac.web.chrome import add_stylesheet, ITemplateProvider, add_warning, web_context
    4747from trac.wiki.api import WikiSystem
     48from trac.wiki.model import WikiPage
    4849from trac.wiki.formatter import format_to_html, format_to_oneliner, Formatter, system_message
    4950from trac.wiki.macros import WikiMacroBase
    5051
    class MarkdownFormatter(Component): 
    148149        def wiki_to_html(self, context, wikidom, escape_newlines=None):
    149150            return Markup(format_to_markdown(self, context, wikidom))
    150151
    151         if template and data and 'page' in data:
     152        if template and data and isinstance(data.get('page'), WikiPage):
    152153            # We only handle wiki pages
    153154            path = data['page'].name.split('/')
    154155            if path[0] in self.root_pages:

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Cinc-th.

Add Comment


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

 
Note: See TracTickets for help on using tickets.