librelist archives

« back to archive

Mysterious error with ImmutableMultiDict

Mysterious error with ImmutableMultiDict

From:
Sam's Lists
Date:
2012-10-25 @ 00:13
I'm working on converting a very large legacy code base in Python to Flask.

In my code I have the following lines as part of a much larger function...

        print("Start...")
        print("Type of fd:", type(fd))
        print("Value of fd:", pf(fd))
        database = [fd['database']]
        print("End...")

When I run these lines here's what I get:

Start...
Type of fd: <class 'werkzeug.datastructures.ImmutableMultiDict'>
Value of fd: ImmutableMultiDict([('group', u'AD-cases-controls'),
('type', u'Genotypes'), ('search_terms', u'foo'), ('dataset',
u'AD-cases-controlsPublish'), ('RISet', u'BXD'), ('species',
u'drosophila'), ('FormID', u'searchResult')])

"End..." is never printed. The code seems to stop running before this line.

Nothing is logged anywhere.

Now...obviously there should be some type of error thrown, because the
dict doesn't have the key "database".

But there isn't.

(I even confirmed that logging works in Werkzeug's datastructures.py
by purposefully causing an error, etc.)

The only thing returned by the browser is: "Bad Request. The browser
(or proxy) sent a request that this server could not understand."

Why is some sort of error not being generated somewhere?

I'm running Python 2.7.3, Flask 0.9, Werkzeug 0.8.3 on CentOS 5.4.

Thanks!

P.S. Just for completeness here's what logging_tree thinks my logging
configuration is:

(I've tried a bunch of variations to try and get some error message or
stack trace...here's where it's at currently)

<--""
   Level INFO
   Handler File '/tmp/flask_gn_log'
   |
   o<--[requests]
   |   |
   |   o<--[requests.packages]
   |       |
   |       o<--"requests.packages.urllib3"
   |           Handler <logging.NullHandler object at 0x15802090>
   |           |
   |           o<--"requests.packages.urllib3.connectionpool"
   |           |
   |           o<--"requests.packages.urllib3.poolmanager"
   |           |
   |           o<--"requests.packages.urllib3.response"
   |
   o<--"search"
   |   Handler Stream <open file '<stderr>', mode 'w' at 0x2b78f04c2270>
   |
   o<--"werkzeug"
   |
   o<--"wqflask"
       Handler <flask.logging.DebugHandler object at 0x16129e50>
       Handler File '/tmp/flask_gn_log'

Re: [flask] Mysterious error with ImmutableMultiDict

From:
Steven Kryskalla
Date:
2012-10-25 @ 00:39
On Wed, Oct 24, 2012 at 5:13 PM, Sam's Lists <samslists@gmail.com> wrote:
> Nothing is logged anywhere.
>
> Now...obviously there should be some type of error thrown, because the
> dict doesn't have the key "database".
>
> But there isn't.
>
> (I even confirmed that logging works in Werkzeug's datastructures.py
> by purposefully causing an error, etc.)
>
> The only thing returned by the browser is: "Bad Request. The browser
> (or proxy) sent a request that this server could not understand."
>
> Why is some sort of error not being generated somewhere?

Try setting this in your app config:

app.config['TRAP_BAD_REQUEST_ERRORS'] = True

I think you are running into flask's behavior of turning key errors
into a "400 Bad Request" response with no log message or exception
thrown. I was pretty confused as well.

-Steve