#12704 closed defect (fixed)
TypeError: unicode argument expected, got 'str'
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 |
||
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'
Attachments (1)
Change History (12)
comment:1 by , 8 years ago
Milestone: | → 1.3.2 |
---|---|
Version: | → 1.3dev |
comment:2 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
Release Notes: | modified (diff) |
---|
by , 8 years ago
Attachment: | Screen Shot 2017-02-27 at 22.57.27.png added |
---|
follow-up: 6 comment:4 by , 8 years ago
Fixed in r15593, however I think we should preventing allowing to create a report with empty SQL query.
follow-up: 7 comment:5 by , 8 years ago
When no SQL query error occurs, Edit and Delete buttons would be invisible. The buttons should be visible.
comment:6 by , 8 years ago
Replying to Ryan J Ollos:
Fixed in r15593, however I think we should preventing allowing to create a report with empty SQL query.
Simplest way to avoid empty query would be:
-
trac/ticket/model.py
diff --git a/trac/ticket/model.py b/trac/ticket/model.py index 7f65e5c03..2c9d39330 100644
a b class Report(object): 1189 1189 def insert(self): 1190 1190 """Insert a new report.""" 1191 1191 assert not self.exists, "Cannot insert existing report" 1192 if not self.query: 1193 raise TracError(_("Query cannot be empty.")) 1192 1194 1193 1195 self.env.log.debug("Creating new report '%s'", self.id) 1194 1196 with self.env.db_transaction as db: … … class Report(object): 1199 1201 self.id = db.get_last_id(cursor, 'report') 1200 1202 1201 1203 def update(self): 1204 if not self.query: 1205 raise TracError(_("Query cannot be empty.")) 1202 1206 self.env.db_transaction(""" 1203 1207 UPDATE report SET title=%s, query=%s, description=%s 1204 1208 WHERE id=%s
I think it would be good to add a warning instead, but we should make those changes throughout TRac. For example, when adding a milestone with empty name.
follow-up: 8 comment:7 by , 8 years ago
Replying to Jun Omae:
When no SQL query error occurs, Edit and Delete buttons would be invisible. The buttons should be visible.
Agreed, but that is unrelated to the regression and 1.2-stable has same issue. We can avoid by preventing saving a report with an empty query.
follow-up: 9 comment:8 by , 8 years ago
Replying to Ryan J Ollos:
Replying to Jun Omae:
When no SQL query error occurs, Edit and Delete buttons would be invisible. The buttons should be visible.
Agreed, but that is unrelated to the regression and 1.2-stable has same issue.
Yeah. I'll create new ticket for invisible buttons. → #12709
We can avoid by preventing saving a report with an empty query.
Minor thing, we cannot avoid empty saved query before the fix. I manually added ?action=edit
to URL.
comment:9 by , 8 years ago
Replying to Jun Omae:
We can avoid by preventing saving a report with an empty query.
Minor thing, we cannot avoid empty saved query before the fix. I manually added
?action=edit
to URL.
Good point. I think it's a good idea to show those buttons on the page even when an error is raised.
comment:10 by , 8 years ago
API Changes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
comment:11 by , 8 years ago
Release Notes: | modified (diff) |
---|
This appears to be due to changes in #12046. It seems to be fixed with either of these patches:
trac/ticket/model.py
''''''trac/ticket/report.py
expr))Is one of those preferred, or is there an even better fix? I'll add a unit test before committing.