librelist archives

« back to archive

The teardown_request can not get exception object under debug mode (always None, but normal when debug=True)?

The teardown_request can not get exception object under debug mode (always None, but normal when debug=True)?

From:
Terry Zhao
Date:
2013-05-12 @ 23:42
I want to rollback my db session while exception happens, so I tried:

@app.teardown_requestdef teardown_request(exception):
    print "Teardown 1 {0!r}".format(exception)
    if exception:
        print ">>>> Exception Happaned <<<<"
        db.session.rollback()
        db.session.remove()
    print "good"
    db.session.remove()

 I tested to raise an exception by forcing my code to error, even using
this:

raise Exception("bacoff")

 But it always print "Teardown 1 None" and "good".

*What confused me is once I close the DEBUG mode by app.run(debug=False),
the exception shows right:*

Teardown 1 Exception('bacoff',)>>>> Exception Happaned <<<<
good

so, I don't know is this a bug of Flask framework, or my configuration
fault...

Please help correct this, thanks in advance.

My ENV is:

   - BeautifulSoup 3.2.1
   - Flask 0.9
   - Flask-Login 0.1.3
   - Flask-Mail 0.8.2
   - Flask-OpenID 1.1.1
   - Flask-SQLAlchemy 0.16
   - Flask-WTF 0.8.3
   - Flask-WhooshAlchemy 0.55a
   - Jinja2 2.6
   - SQLAlchemy 0.8.1
   - Tempita 0.5.1
   - WTForms 1.0.3
   - Werkzeug 0.8.3
   - Whoosh 2.4.1
   - blinker 1.2
   - decorator 3.4.0
   - lxml 3.2.0
   - pycurl 7.19.0
   - python-openid 2.2.5
   - requests 1.2.0
   - sqlalchemy-migrate 0.7.2
   - wsgiref 0.1.2


-- 
Thanks & Best Regards.
赵慧 / Terry Zhao

Re: [flask] The teardown_request can not get exception object under debug mode (always None, but normal when debug=True)?

From:
Mark Steve Samson
Date:
2013-05-13 @ 02:18
Nope it's not a configuration issue. The werkzeug debugger swallows the
exception.


On Mon, May 13, 2013 at 7:42 AM, Terry Zhao <huiyubird@gmail.com> wrote:

> I want to rollback my db session while exception happens, so I tried:
>
>
> @app.teardown_requestdef teardown_request(exception):
>     print "Teardown 1 {0!r}".format(exception)
>     if exception:
>         print ">>>> Exception Happaned <<<<"
>         db.session.rollback()
>         db.session.remove()
>     print "good"
>     db.session.remove()
>
>  I tested to raise an exception by forcing my code to error, even using
> this:
>
>
> raise Exception("bacoff")
>
>  But it always print "Teardown 1 None" and "good".
>
> *What confused me is once I close the DEBUG mode by app.run(debug=False),
> the exception shows right:*
>
>
> Teardown 1 Exception('bacoff',)>>>> Exception Happaned <<<<
> good
>
> so, I don't know is this a bug of Flask framework, or my configuration
> fault...
>
> Please help correct this, thanks in advance.
>
> My ENV is:
>
>    - BeautifulSoup 3.2.1
>    - Flask 0.9
>    - Flask-Login 0.1.3
>    - Flask-Mail 0.8.2
>    - Flask-OpenID 1.1.1
>    - Flask-SQLAlchemy 0.16
>    - Flask-WTF 0.8.3
>    - Flask-WhooshAlchemy 0.55a
>    - Jinja2 2.6
>    - SQLAlchemy 0.8.1
>    - Tempita 0.5.1
>    - WTForms 1.0.3
>    - Werkzeug 0.8.3
>    - Whoosh 2.4.1
>    - blinker 1.2
>    - decorator 3.4.0
>    - lxml 3.2.0
>    - pycurl 7.19.0
>    - python-openid 2.2.5
>    - requests 1.2.0
>    - sqlalchemy-migrate 0.7.2
>    - wsgiref 0.1.2
>
>
> --
> Thanks & Best Regards.
> 赵慧 / Terry Zhao
>

Re: [flask] The teardown_request can not get exception object under debug mode (always None, but normal when debug=True)?

From:
Mark Steve Samson
Date:
2013-05-13 @ 02:35
Oops sorry. Wrong answer. Check this out:
https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L1254


On Mon, May 13, 2013 at 10:18 AM, Mark Steve Samson <hello@marksteve.com>wrote:

> Nope it's not a configuration issue. The werkzeug debugger swallows the
> exception.
>
>
> On Mon, May 13, 2013 at 7:42 AM, Terry Zhao <huiyubird@gmail.com> wrote:
>
>> I want to rollback my db session while exception happens, so I tried:
>>
>> @app.teardown_requestdef teardown_request(exception):
>>     print "Teardown 1 {0!r}".format(exception)
>>     if exception:
>>         print ">>>> Exception Happaned <<<<"
>>         db.session.rollback()
>>         db.session.remove()
>>     print "good"
>>     db.session.remove()
>>
>>  I tested to raise an exception by forcing my code to error, even using
>> this:
>>
>> raise Exception("bacoff")
>>
>>  But it always print "Teardown 1 None" and "good".
>>
>> *What confused me is once I close the DEBUG mode by app.run(debug=False),
>> the exception shows right:*
>>
>> Teardown 1 Exception('bacoff',)>>>> Exception Happaned <<<<
>> good
>>
>> so, I don't know is this a bug of Flask framework, or my configuration
>> fault...
>>
>> Please help correct this, thanks in advance.
>>
>> My ENV is:
>>
>>    - BeautifulSoup 3.2.1
>>    - Flask 0.9
>>    - Flask-Login 0.1.3
>>    - Flask-Mail 0.8.2
>>    - Flask-OpenID 1.1.1
>>    - Flask-SQLAlchemy 0.16
>>    - Flask-WTF 0.8.3
>>    - Flask-WhooshAlchemy 0.55a
>>    - Jinja2 2.6
>>    - SQLAlchemy 0.8.1
>>    - Tempita 0.5.1
>>    - WTForms 1.0.3
>>    - Werkzeug 0.8.3
>>    - Whoosh 2.4.1
>>    - blinker 1.2
>>    - decorator 3.4.0
>>    - lxml 3.2.0
>>    - pycurl 7.19.0
>>    - python-openid 2.2.5
>>    - requests 1.2.0
>>    - sqlalchemy-migrate 0.7.2
>>    - wsgiref 0.1.2
>>
>>
>> --
>> Thanks & Best Regards.
>> 赵慧 / Terry Zhao
>>
>
>