Ticket #10814 (closed defect: fixed)

Opened 4 months ago

Last modified 3 months ago

TypeError: 'int' object is not iterable

Reported by: paulcoddington@hotmail.com Assigned to: rjollos
Priority: normal Component: WikiTableMacro
Severity: blocker Keywords:
Cc: Trac Release: 0.10

Description

TypeError: 'int' object is not iterable

Sample Wiki markup:

{{{
#!SQLTable
    SELECT count(id) as 'Number of Tickets'
    FROM ticket
}}}

Error produced when count of Tickets > 0

Trac 1.0, Windows 7 (x64), Python 2.7.x (x86)

Attachments

Change History

01/25/13 23:50:49 changed by rjollos

I'm not sure if it will be relevant, but what DB are you using?

01/26/13 06:16:32 changed by paulcoddington@hotmail.com

Just the default SQLite DB.

02/04/13 14:35:59 changed by jma

I have the exact same error on Trac v1.0 running on Gentoo Linux and python 2.7

02/21/13 04:49:46 changed by jun66j5

Reproduced. The stacktrace is here.

...
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/wiki/formatter.py", line 343, in _macro_processor
    text)
  File "/home/jun66j5/src/trac/trac-hacks/wikitablemacro/trunk/wikitable/table.py", line 68, in expand_macro
    format_to_html(self.env, formatter.context, col)
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/wiki/formatter.py", line 1546, in format_to_html
    return HtmlFormatter(env, context, wikidom).generate(escape_newlines)
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/wiki/formatter.py", line 1501, in generate
    escape_newlines)
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/wiki/formatter.py", line 1237, in format
    for line in text:
TypeError: 'int' object is not iterable

The 3rd argument, wikidom, of format_to_html expects a instance of str, unicode or iterable.

Index: wikitable/table.py
===================================================================
--- wikitable/table.py  (revision 12643)
+++ wikitable/table.py  (working copy)
@@ -16,7 +16,7 @@
 from trac.wiki.formatter import system_message, format_to_html
 from trac.wiki.macros import WikiMacroBase
 from trac.util.html import Markup
-from trac.util.text import exception_to_unicode
+from trac.util.text import to_unicode, exception_to_unicode
 from trac.util.translation import _

 class SQLTable(WikiMacroBase):
@@ -64,6 +64,14 @@
             css_class = (idx % 2 == 0) and 'odd' or 'even'
             print >> out, "  <tr class='%s'>" % css_class
             for col in row:
+                if col is None:
+                    col = "''(NULL)''"
+                elif col is True:
+                    col = 'TRUE'
+                elif col is False:
+                    col = 'FALSE'
+                elif not isinstance(col, basestring):
+                    col = to_unicode(col)
                 print >> out, "<td>%s</td>" % \
                     format_to_html(self.env, formatter.context, col)
             print >> out, "  </tr>"

02/21/13 22:06:46 changed by rjollos

Thank you for the patch Jun. I'll test and apply it.

I don't have a lot of interest in this macro, so if someone else wants to take over maintenance I'm more than willing to hand it over.

02/21/13 22:25:59 changed by rjollos

  • status changed from new to closed.
  • resolution set to fixed.

(In [12646]) Fixes #10814: Patch by Jun Omae (jun66j5) to fix a regression introduced in [12459]. Ensure that a string is passed to format_to_html.

Lightly tested against Trac 1.1.2dev-r11682.


Add/Change #10814 (TypeError: 'int' object is not iterable)




Change Properties
Action