Edgewall Software

Opened 7 years ago

Last modified 7 years ago

#12704 closed defect

TypeError: unicode argument expected, got 'str' — at Version 3

Reported by: anonymous Owned by: Ryan J Ollos
Priority: normal Milestone: 1.3.2
Component: report system Version: 1.3dev
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fixed TypeError when report is saved when an empty SQL query.

API Changes:
Internal Changes:

Description

Creating a new report with an empty query field:

Traceback (most recent call last):
  File "/trac/trunk/trac/web/main.py", line 630, in _dispatch_request
    dispatcher.dispatch(req)
  File "/trac/trunk/trac/web/main.py", line 252, in dispatch
    resp = chosen_handler.process_request(req)
  File "/trac/trunk/trac/ticket/report.py", line 190, in process_request
    template, data, content_type = self._render_view(req, id)
  File "/trac/trunk/trac/ticket/report.py", line 422, in _render_view
    res = self.execute_paginated_report(req, id, sql, args, limit, offset)
  File "/trac/trunk/trac/ticket/report.py", line 659, in execute_paginated_report
    sql, args, missing_args = self.sql_sub_vars(sql, args)
  File "/trac/trunk/trac/ticket/report.py", line 846, in sql_sub_vars
    sql_io.write(sub_vars_re.sub(repl, expr))
TypeError: unicode argument expected, got 'str'

Change History (4)

comment:1 by Jun Omae, 7 years ago

Milestone: 1.3.2
Version: 1.3dev

comment:2 by Ryan J Ollos, 7 years ago

Owner: set to Ryan J Ollos
Status: newassigned

This appears to be due to changes in #12046. It seems to be fixed with either of these patches:

  • trac/ticket/model.py

    diff --git a/trac/ticket/model.py b/trac/ticket/model.py
    index 9cec28d12..21ceb87e3 100644
    a b class Report(object):  
    11671167                        WHERE id=%s
    11681168                        """, (id_as_int,)):
    11691169                    self.id = id_as_int
    1170                     self.title = title or ''
    1171                     self.description = description or ''
    1172                     self.query = query or ''
     1170                    self.title = title or u''
     1171                    self.description = description or u''
     1172                    self.query = query or u''
    11731173                    return
    11741174            raise ResourceNotFound(_("Report {%(num)s} does not exist.",
    11751175                                     num=id), _("Invalid Report Number"))
  • trac/ticket/report.py

    diff --git a/trac/ticket/report.py b/trac/ticket/report.py
    index 12e7bf9c1..c3ebc1145 100644
    a b class ReportModule(Component):  
    843843                if expr.startswith("'"):
    844844                    sql_io.write(repl_literal(expr, db))
    845845                else:
    846                     sql_io.write(sub_vars_re.sub(repl, expr))
     846                    sql_io.write(sub_vars_re.sub(repl, unicode(expr)))
    847847
    848848        # Remove arguments that don't appear in the SQL query
    849849        for name in set(args) - names:

Is one of those preferred, or is there an even better fix? I'll add a unit test before committing.

comment:3 by Ryan J Ollos, 7 years ago

Release Notes: modified (diff)

by Ryan J Ollos, 7 years ago

Note: See TracTickets for help on using tickets.