Ticket #36 (assigned enhancement)

Opened 3 years ago

Last modified 3 years ago

Have WSGIServer warn when someone returns a string from their application

Reported by: trac Assigned to: asaddi (accepted)
Priority: minor Milestone:
Component: flup.server Version: 1.0.1
Keywords: errors debug Cc:

Description

When someone (dumb, like me) returns a string from the application they pass to WSGIServer, warn the user that it's dumb, and broken.

i.e.

# super-simple app
def myapp
    return "This is my string ... I'm nestled among a big list of other returns, so I'm hard to find."
   # instead of
   # return ["This makes WSGIServer do happy things"]

# Somewhere in here this should warn ... Returning strings is dumb, and wrong.
WSGIServer(myapp).run()

I just spent 4 hours figuring that out, so I thought I'd share. (I suppose an assert might be grand, especially since you can -O them out)

Alternatively, WSGIServer could check to see if it's getting a string, and not interpret it as an interable ...

Cheers

Change History

12/02/08 00:17:28 changed by asaddi

  • status changed from new to assigned.

Well, maybe not an assert since technically returning a string is legal. (And for the same reasons, I'm not too in favor of treating strings as special.)

Anyhow, have you looked at wsgiref.validate? When I do WSGI development, I find it very helpful to wrap just about everything (middleware, app) in the validator. It catches issues like this.

I'll see about adding a check though, it seems simple enough. Perhaps emit a warning to the error stream if there's a problem. And I can make it conditional (based on debug), so it will go away with -O like an assert.

02/03/09 00:01:49 changed by asaddi

  • milestone deleted.

Actually, I'm having second thoughts about adding code for this. Removing from 1.0.2 while I mull over it.