Ticket #1502 (closed defect: invalid)

Opened 1 year ago

Last modified 2 months ago

[PATCH] Controller and fileupload field.

Reported by: mconte Assigned to: faide
Priority: normal Milestone: 1.5
Component: TurboGears Version: 1.0.4b1
Severity: normal Keywords:
Cc:

Description (Last modified by Chris Arndt)

Using TurboGears with the upload bar example from: http://docs.turbogears.org/1.0/FileUploadProgressBar. I realize that when I post some information that raises an error (for example an invalid form value entered), the application crashes. I lost the trace exception but it was something like:

(... )
  File "/usr/lib/python2.5/site-packages/turbogears/controllers.py,
line 509, in url
     args.append("%s=%s" % (key, urllib.quote(str(value))))
  File "/usr/lib/python2.5/cgi.py", line 541, in __repr__
    self.name, self.filename, self.value)
  File "/usr/lib/python2.5/cgi.py", line 551, in __getattr__
    value = self.file.read()
TypeError: read() takes exactly 2 arguments (1 given)

Looking at controllers.py, lines 539ff looks like:

     for key, value in tgparams.iteritems():
-        if value is None:
             continue
         if isinstance(value, unicode):
             value = value.encode("utf8")

I think we don't want to include file info, so i changed to:

     for key, value in tgparams.iteritems():
+        if value is None or isinstance(value, cgi.FieldStorage):
             continue
         if isinstance(value, unicode):
             value = value.encode("ut

And it's working now. I can attach the patch if it is approved.

Change History

09/20/07 18:33:24 changed by faide

  • owner changed from anonymous to faide.
  • status changed from new to assigned.

It would be interesting to have a patch attached yes :)

Could you also provide a small test that reproduces the crash ? This way we could write a test case to ensure there will be no regression.

And BTW you can use triple accolades to paste code blocks, it is easier to read:

if value is None or isinstance(value, cgi.FieldStorage):
    continue

09/20/07 18:33:37 changed by faide

  • version changed from 1.0.3 to 1.0.4b1.
  • milestone set to 1.0.4.

11/25/07 12:38:09 changed by faide

  • summary changed from Controller and fileupload field. to [PATCH] Controller and fileupload field..

11/25/07 12:41:30 changed by faide

this patch also requires an "import cgi" somewhere in the controllers.py code.

11/25/07 12:43:36 changed by faide

  • milestone changed from 1.0.4 to 1.1.

08/22/08 11:27:17 changed by Chris Arndt

  • status changed from assigned to closed.
  • resolution set to invalid.
  • description changed.

I suspect that this "patch" tries to cure a symptom rather than the cause. The url() function does not handle arbitrary objects as values for the tgparams or the keyword parameters, only (unicode) strings or lists/tuples thereof. I further suspect that the error described results from an improper use of an error_handler or a redirect but without example code or a testcase it is impossible to tell for sure.

For the above reasons and since this ticket has not received any feedback for almost a year I'm closing it as invalid.