Ticket #9730 (closed defect: fixed)

Opened 4 months ago

Last modified 1 month ago

"AttributeError: 'list' object has no attribute 'decode'"

Reported by: snoopotic Assigned to: farialima
Priority: normal Component: TicketImportPlugin
Severity: normal Keywords:
Cc: jun66j5 Trac Release: 0.12

Description

Hi, trying to import a csv or something else errors at:

2012-01-26 10:16:28,645 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/Trac-0.12.2-py2.6.egg/trac/web/main.py", line 511, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.6/site-packages/Trac-0.12.2-py2.6.egg/trac/web/main.py", line 237, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/importer.py", line 77, in process_request
    encoding=req.session['importer.encoding'])
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/importer.py", line 121, in _do_preview
    return self._process(filereader, get_reporter_id(req), PreviewProcessor(self.env, req))
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/importer.py", line 317, in _process
    for row in rows:
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/readers.py", line 60, in next
    return dict((_to_unicode(key), _to_unicode(val)) for key, val in d.iteritems())
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/readers.py", line 60, in <genexpr>
    return dict((_to_unicode(key), _to_unicode(val)) for key, val in d.iteritems())
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/readers.py", line 45, in _to_unicode
    return val.decode('utf-8')
AttributeError: 'list' object has no attribute 'decode'

But I also possibly found the solution: Change in readers.py (of ver. 0.8.2):

 42 def _to_unicode(val):
 43     if val is None or isinstance(val, unicode):
 44         return val
 45     return val.decode('utf-8')

to:

 42 def _to_unicode(val):
 43     if val is None or isinstance(val, unicode):
 44         return val[0]
 45     return val[0].decode('utf-8')

Attachments

Anf_test_OK.csv (409 bytes) - added by snoopotic on 01/27/12 09:34:42.
csv that is ok
Anf_test_NOTOK.csv (429 bytes) - added by snoopotic on 01/27/12 09:35:05.
csv that is not ok

Change History

01/26/12 10:59:07 changed by farialima

Hello snoopotic - could you attach a .csv file that exposes the problem ? I'd love to take your patch but would like to add a testcase too..

01/27/12 09:34:07 changed by snoopotic

sorry, I think this case can be closed as wontfix: The CSV we used had errors: first line was defining the fields with 5 separations but some lines beneath the "description" part contained also some ";" (semicolon) that were interpreted as separators and this error appeared. I attached the csvs. Maybe there can be implemented an improvement not to throw that Exception but a Warning that the csv is nod valid - so you know to look into the csv.

btw: with my change you don't get this warning but also the valid one does not work :/

Sorry for that.

01/27/12 09:34:42 changed by snoopotic

  • attachment Anf_test_OK.csv added.

csv that is ok

01/27/12 09:35:05 changed by snoopotic

  • attachment Anf_test_NOTOK.csv added.

csv that is not ok

01/28/12 16:02:37 changed by jun66j5

(In [11210]) Ignores more field values than the field names (refs #9730).

01/28/12 16:08:17 changed by jun66j5

  • cc set to jun66j5.

Hi snoopotic,

I can reproduce the issue when a row has more fields than the field names. In [11210], ignores simply the values. Please try the latest if you can. Thanks.

04/27/12 21:36:18 changed by jun66j5

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

Already fixed


Add/Change #9730 ("AttributeError: 'list' object has no attribute 'decode'")




Change Properties
Action