Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1502 (closed defect: invalid)

Opened 11 years ago

Last modified 10 years ago

[PATCH] Controller and fileupload field.

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

Description (last modified by Chris Arndt) (diff)

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

comment:1 Changed 11 years ago 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

comment:2 Changed 11 years ago by faide

  • Version changed from 1.0.3 to 1.0.4b1
  • Milestone set to 1.0.4

comment:3 Changed 11 years ago by faide

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

comment:4 Changed 11 years ago by faide

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

comment:5 Changed 11 years ago by faide

  • Milestone changed from 1.0.4 to 1.1

comment:6 Changed 10 years ago by Chris Arndt

  • Status changed from assigned to closed
  • Resolution set to invalid
  • Description modified (diff)

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.

Note: See TracTickets for help on using tickets.