Edgewall Software
Modify

Opened 17 years ago

Closed 14 years ago

Last modified 12 years ago

#5812 closed defect (wontfix)

[PATCH] Spamfilter monitor exception.

Reported by: grafikrobot@… Owned by: Matthew Good
Priority: normal Milestone:
Component: plugin/spamfilter Version: 0.10.4
Severity: normal Keywords: unicode python23
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

In the Boost trac we are getting a Python exception while trying to look at the spam log in the admin interface as:

Traceback (most recent call last):
  File "/opt/trac/lib/python2.3/site-packages/trac/web/main.py", line 406, in dispatch_request
    dispatcher.dispatch(req)
  File "/opt/trac/lib/python2.3/site-packages/trac/web/main.py", line 237, in dispatch
    resp = chosen_handler.process_request(req)
  File "/opt/trac/boost/plugins/TracWebAdmin-0.1.2dev_r4240-py2.3.egg/webadmin/web_ui.py", line 109, in process_request
  File "build/bdist.linux-i686/egg/tracspamfilter/admin.py", line 91, in process_admin_request
  File "build/bdist.linux-i686/egg/tracspamfilter/admin.py", line 81, in render_admin_panel
  File "build/bdist.linux-i686/egg/tracspamfilter/admin.py", line 178, in _render_monitoring_panel
  File "build/bdist.linux-i686/egg/tracspamfilter/model.py", line 265, in select
  File "build/bdist.linux-i686/egg/tracspamfilter/model.py", line 272, in _from_db
  File "build/bdist.linux-i686/egg/tracspamfilter/model.py", line 82, in _decode_content
AttributeError: 'unicode' object has no attribute 'decode'

Attachments (2)

model.py.a.patch (720 bytes ) - added by grafikrobot@… 16 years ago.
Ensure decode is called on str.
model.py.b.patch (435 bytes ) - added by grafikrobot@… 16 years ago.
Handle the AttributeError exception, and assume string is not base64 encoded.

Download all attachments as: .zip

Change History (13)

comment:1 by Emmanuel Blot, 17 years ago

Please specify which version of Trac you're using

comment:2 by grafikrobot@…, 17 years ago

Version: 0.10.4

Per the link provided to the running trac instance, 0.10.4.

comment:3 by Tim Hatch, 17 years ago

I checked on Python 2.3.5 and the unicode type indeed doesn't have a decode method in that version.

comment:4 by sid, 16 years ago

So the suggested course of action is to upgrade to a later python version then?

comment:5 by Christian Boos, 16 years ago

Keywords: unicode python23 added
Milestone: not applicable

comment:6 by grafikrobot@…, 16 years ago

Looking at the current code it seems there's an expectation that the DB, sqlite in the Boost case, will return "str" and not "unicode" strings. There are two "solutions" I can think of:

  • Handle the AttributeError and assume it means the result is not base64.
  • Ensure the decode('base64') is called only on an "str" object.

I'm attaching two patches for each one of those. But note that they are not tested in any form since I just don't know enough about the rest of the spamfilter context to know if they are entirely appropriate. And testing them directly on the Boost Trac install in not feasible (and I don't have an equivalent spare trac to test this on).

by grafikrobot@…, 16 years ago

Attachment: model.py.a.patch added

Ensure decode is called on str.

by grafikrobot@…, 16 years ago

Attachment: model.py.b.patch added

Handle the AttributeError exception, and assume string is not base64 encoded.

comment:7 by anonymous, 15 years ago

I'm experiencing this problem. My output is slightly different:

File "/usr/lib/python2.3/site-packages/Trac-0.11.3-py2.3.egg/trac/web/main.py", line 435, in _dispatch_request
  dispatcher.dispatch(req)
File "/usr/lib/python2.3/site-packages/Trac-0.11.3-py2.3.egg/trac/web/main.py", line 205, in dispatch
  resp = chosen_handler.process_request(req)
File "/usr/lib/python2.3/site-packages/Trac-0.11.3-py2.3.egg/trac/admin/web_ui.py", line 113, in process_request
  path_info)
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/admin.py", line 81, in render_admin_panel
  data = self._render_monitoring_panel(req, cat, page)
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/admin.py", line 178, in _render_monitoring_panel
  offset=offset))
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/model.py", line 265, in select
  yield cls._from_db(env, row)
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/model.py", line 272, in _from_db
  fields[6] = cls._decode_content(fields[6])
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/model.py", line 82, in _decode_content
  return to_unicode(content.decode('base64'))

comment:8 by anonymous, 15 years ago

Summary: Spamfilter monitor exception.[PATCH] Spamfilter monitor exception.

comment:9 by Christian Boos, 14 years ago

Resolution: wontfix
Status: newclosed

#7118 was closed as duplicate.

The following error:

>>> u'sasd='.decode('base64')
AttributeError: 'unicode' object has no attribute 'decode'

is specific to Python 2.3.

In Python 2.4 and higher, it's perfectly legit:

>>> u'sasd='.decode('base64')
'\xb1\xab\x1d'

The content should be base64 encoded, otherwise will get one of the errors that we already check for.

I close it as wontfix, as I don't want to start adding more support for Python 2.3 at this point.

comment:10 by Christian Boos, 14 years ago

(Michael, just remembering that you have commit rights on that plugin, and if your intent was to add support for Python 2.3, then please feel free to do so, just doing a str() cast would be enough).

comment:11 by Christian Boos, 12 years ago

Milestone: not applicable

(clearing report:35)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Matthew Good.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Matthew Good to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.