Edgewall Software
Modify

Opened 8 years ago

Closed 6 years ago

#4311 closed defect (fixed)

AttributeError: 'cStringIO.StringO' object has no attribute 'len'

Reported by: anonymous Owned by: mgood
Priority: high Milestone: 0.10.4
Component: general Version: 0.10.2
Severity: normal Keywords: python25
Cc:
Release Notes:
API Changes:

Description

Attaching files doesn't seem to work correctly anymore. This is Trac 0.10.2 and Python 2.5.

Python Traceback

Traceback (most recent call last):
  File "/usr/lib64/python2.5/site-packages/trac/web/main.py", line 387, in dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib64/python2.5/site-packages/trac/web/main.py", line 238, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib64/python2.5/site-packages/trac/attachment.py", line 361, in process_request
    self._do_save(req, attachment)
  File "/usr/lib64/python2.5/site-packages/trac/attachment.py", line 449, in _do_save
    size = upload.file.len
AttributeError: 'cStringIO.StringO' object has no attribute 'len'

Attachments (0)

Change History (24)

comment:1 Changed 8 years ago by ThurnerRupert

what platform are you on?

comment:2 Changed 8 years ago by anonymous

Linux 2.6.18, x86_64, SuSE.

comment:3 in reply to: ↑ description Changed 8 years ago by eblot

Replying to anonymous:

Attaching files doesn't seem to work correctly anymore. This is Trac 0.10.2 and Python 2.5.

I don't think this is related to this very issue, but Trac 0.10 is known to have issues when run with Python 2.5, due to issues w/ ClearSilver.

comment:4 Changed 8 years ago by mgood

  • Keywords needinfo added

Which web frontend are you using? FastCGI, mod_python, CGI, etc.? Which web server?

comment:5 Changed 8 years ago by stepan@…

No fastcgi afaik

apache2-2.2.3-20 apache2-mod_python-3.2.10-27 python-2.5-19

what else do you need to know?

comment:6 Changed 8 years ago by mgood

  • Keywords needinfo removed
  • Milestone set to 0.10.3

Hmm, Python 2.5 changed the cgi module to use cStringIO for files if it's available, which unlike the StringIO object doesn't support reading the length. I guess we need to find another way to check the size of the uploaded file.

comment:7 Changed 8 years ago by Stefan Reinauer <stepan@…>

My oh my.. I am not becoming a python fan. After wasting about 5h with wild guesses and restarting apache I found the following workaround seems to do it for my small test file. Don't know if it is worth anything.

if hasattr(upload.file, 'fileno'):

size = os.fstat(upload.file.fileno())[6]

else:

fstr = StringIO.StringIO(upload.file) size = fstr.len

comment:8 Changed 8 years ago by anonymous

I found the same error and observed that the error comes up, if the size of the uploaded file is smaller than 1kByte (approx.) Maybe this helps to find the reason.

comment:9 Changed 8 years ago by cboos

  • Component changed from ticket system to mod_python frontend
  • Keywords python25 added
  • Owner changed from jonas to cmlenz

comment:10 Changed 8 years ago by mgood

  • Component changed from mod_python frontend to general
  • Owner changed from cmlenz to jonas

This is not specific to mod_python. The problem is due to the change in the Python cgi module which is used by Trac for parsing POSTs on all frontends.

comment:11 follow-up: Changed 8 years ago by thatch

I think using the file-like interface ought to work since StringIO and cStringIO both provide it. This is constant time for both modules.

Tested on Python 2.4 and it works. Analysis of 2.5's source for cStringIO shows it should work too.

  • trac/attachment.py

     
    448448        if hasattr(upload.file, 'fileno'):
    449449            size = os.fstat(upload.file.fileno())[6]
    450450        else:
    451             size = upload.file.len
     451            upload.file.seek(0, 2)
     452            size = upload.file.tell()
     453            upload.file.seek(0)
    452454        if size == 0:
    453455            raise TracError("Can't upload empty file")

comment:12 in reply to: ↑ 11 Changed 8 years ago by mgood

  • Owner changed from jonas to mgood
  • Status changed from new to assigned

Replying to thatch:

I think using the file-like interface ought to work since StringIO and cStringIO both provide it. This is constant time for both modules.

Aha, yes I figured there should be some other way to check the size, but I missed that seek() supported seeking relative to the end of the file. That should do the trick.

comment:13 Changed 8 years ago by mgood

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in r4459 and r4460. Thanks for the patch.

comment:14 follow-up: Changed 8 years ago by demarco@…

This bug is triggered by attempting to upload a vCard / vcf. These keywords should help others avoid submitting duplicate bugs.

comment:15 in reply to: ↑ 14 Changed 8 years ago by mgood

Replying to demarco@maya.com:

This bug is triggered by attempting to upload a vCard / vcf. These keywords should help others avoid submitting duplicate bugs.

The problem is not dependent on the file type. It was an issue with an internal API that changed in Python 2.5.

comment:16 Changed 7 years ago by kap4020@…

Yup, I have this problem too:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=7.04
DISTRIB_CODENAME=feisty
DISTRIB_DESCRIPTION="Ubuntu 7.04"

But, the patch fixed things for me. =)

comment:17 Changed 7 years ago by Didactylos

  • Resolution fixed deleted
  • Status changed from closed to reopened

I am experiencing this bug in Trac 0.10.4 when trying to attach a file to a template.

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 406, in dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 237, in dispatch
    resp = chosen_handler.process_request(req)
  File "build/bdist.linux-i686/egg/WikiTemplates/attachment.py", line 363, in process_request
    self._do_save(req, attachment)
  File "build/bdist.linux-i686/egg/WikiTemplates/attachment.py", line 455, in _do_save
    size = upload.file.len
AttributeError: 'cStringIO.StringO' object has no attribute 'len'

comment:18 Changed 7 years ago by cboos

  • Resolution set to fixed
  • Status changed from reopened to closed

Well, as you could see by following the link to r4459, that size = upload.file.len line has been replaced for 0.10.4. So if you're having that line in your backtrace, you're not running 0.10.4 (and installing Trac as an egg is not supported for versions before 0.11dev).

comment:19 Changed 7 years ago by Didactylos

  • Resolution fixed deleted
  • Status changed from closed to reopened

Look again: this is when attaching a file to a template. I'm a Trac user, not an administrator - so I'm just reporting the bug. I know nothing of eggs. If the bug needs to go elsewhere, or is a separate issue, then please do what needs doing. I'm reporting it here because it is an identical bug to the previously fixed bug - just in a different place.

comment:20 Changed 7 years ago by cboos

  • Resolution set to fixed
  • Status changed from reopened to closed

Ok, my bad, but that bug should be reported on http://wikitemplates.ufsoft.org/, where the WikiTemplates? plugin is developed.

Closing again the ticket, as the problem is fixed in Trac itself.

comment:21 Changed 7 years ago by Alexo

You should also patch this line

size = f.len

with

f.seek(0, 2) size = f.tell() f.seek(0)

For newer cStringIO.

Cheers.

Alexo

comment:22 Changed 7 years ago by anonymous

Well, -as you could see by following the link to r4459, that size = upload.file.len line has been replaced for 0.10.4. So if you're having that line in your backtrace, you're not running 0.10.4 (and installing Trac as an egg is not supported for versions before 0.11dev).

comment:23 Changed 6 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

I have this error, if try to download small file (less then 1 kb).

My system Information: Trac: 0.11.1; Python: 2.5.2; TracDownloads?: 0.2.

File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 423, in _dispatch_request
  dispatcher.dispatch(req)
File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 197, in dispatch
  resp = chosen_handler.process_request(req)
File "/usr/lib/python2.5/site-packages/trac/admin/web_ui.py", line 113, in process_request
  path_info)
File "build/bdist.linux-x86_64/egg/tracdownloads/admin.py", line 43, in render_admin_panelFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 353, in process_downloadsFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 534, in _do_actionFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 813, in _get_file_from_req

comment:24 Changed 6 years ago by cboos

  • Resolution set to fixed
  • Status changed from reopened to closed
...
line 534, in _do_actionFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 813, in _get_file_from_req

Please report this to TH:DownloadsPlugin.

The problem in Trac itself was fixed for 0.10.4 (see comment:13).

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain mgood.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from mgood 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.