TracHours plugin - updating for Trac 1.6 - AttributeError: 'str' object has no attribute 'setdefault'

19 views
Skip to first unread message

Rob Hills

unread,
Aug 26, 2025, 8:45:49 AMAug 26
to Trac Users
I posted this on the Trac Hacks group but got no replies.  Is that group still going?

Should I post the original query here instead?

Cheers,

Rob

RjOllos

unread,
Aug 26, 2025, 1:16:21 PMAug 26
to Trac Users
On Tuesday, August 26, 2025 at 5:45:49 AM UTC-7 rcp....@gmail.com wrote:
I posted this on the Trac Hacks group but got no replies.  Is that group still going?

It's dead.
 

Should I post the original query here instead?

Yes, please do. 

Rob Hills

unread,
Aug 26, 2025, 9:59:09 PMAug 26
to Trac Users
I'm using https://trac.edgewall.org/wiki/TracDev/PortingFromGenshiToJinja as a guide to help me update the TracHours plugin to work with Trac 1.6

I have implemented the IRequestFilter interface and added a post_process_request() method which returns three results:  template, data and content_type, as shown in the Porting from Genshi to Jinja howto.  The content_type variable is passed in via the method call and not altered, and is the string "text/html"

However, when this gets processed via trac.web.main here, the content_type variable returned by the post_process_request() method gets transferred into the metadata variable and a few lines down here, the code expects metadata to have a "setdefault" method.  As it's a string, it doesn't have this method and hence throws the AttributeError "''str' object has no attribute 'setdefault'".

I suspect I'm doing something wrong in my code, but I'm not sure what!

Rob Hills
Waikiki, Western Australia

Jun Omae

unread,
Aug 27, 2025, 4:25:05 AMAug 27
to trac-...@googlegroups.com

The post_process_request receives the returned values from process_request. For Jinja2 templates, the process_request should return a tuple of (template, data).

See https://trac.edgewall.org/wiki/TracDev/PortingFromGenshiToJinja#IRequestHandler

Therefore, before implementing IRequestFilter interface, the returned values of process_request should be modified and the template should be ported to Jinja2 from Genshi.

Index: trachours/hours.py
===================================================================
--- trachours/hours.py  (revision 18705)
+++ trachours/hours.py  (working copy)
@@ -384,8 +384,8 @@
             data['queries'] = get_all_dict(self.env, """
                 SELECT id, title, description, query FROM ticket_time_query
                 """)
-            return 'hours_listqueries.html', data, 'text/html'
-        return 'hours_savequery.html', data, 'text/html'
+            return 'hours_listqueries.html', data
+        return 'hours_savequery.html', data

     def process_query(self, req):
         """redict to save, edit or delete a query based on arguments"""
@@ -842,7 +842,7 @@
         add_stylesheet(req, 'common/css/report.css')
         add_script(req, 'common/js/query.js')

-        return 'hours_timeline.html', data, 'text/html'
+        return 'hours_timeline.html', data

     def process_ticket(self, req):
         """process a request to /hours/<ticket number>"""
@@ -901,7 +901,7 @@
         add_ctxtnav(req, 'Back to Ticket #%s' % ticket_id,
                     req.href.ticket(ticket_id))

-        return 'hours_ticket.html', data, 'text/html'
+        return 'hours_ticket.html', data

     # Methods for transforming data to rss

Index: trachours/multiproject.py
===================================================================
--- trachours/multiproject.py   (revision 18705)
+++ trachours/multiproject.py   (working copy)
@@ -204,7 +204,7 @@

         data['total'] = hours_format % total

-        return 'hours_multiproject.html', data, 'text/html'
+        return 'hours_multiproject.html', data


 if __name__ == '__main__':
Index: trachours/web_ui.py
===================================================================
--- trachours/web_ui.py (revision 18705)
+++ trachours/web_ui.py (working copy)
@@ -311,7 +311,7 @@
         #         _('Next Week'))
         # prevnext_nav(req, _('Prev Week'), _('Next Week'))

-        return 'hours_users.html', data, "text/html"
+        return 'hours_users.html', data

     def user(self, req, user):
         """hours page for a single user"""
@@ -360,7 +360,7 @@

             req.send(buffer.getvalue(), 'text/csv')

-        return 'hours_user.html', data, 'text/html'
+        return 'hours_user.html', data

     def export_csv(self, req, data, sep=',', mimetype='text/csv'):
         content = StringIO()
--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/trac-users/3341c5e4-b7a9-4d44-b121-daba8f3a05ecn%40googlegroups.com.
-- 
Jun Omae <jun...@gmail.com> (大前 潤)
Reply all
Reply to author
Forward
0 new messages