On Thursday 28 January 2010 12:47:38 A. wrote:
> Hi all,
>
> I'm using tg1.1 with sqlalchemy
> I'm trying to manage all exceptions using @exception_handler
> decorator. It works fine for ValueError, TypeError etc.
> But for now I am unable to deal with Database Errors using this same
> technique:
>
> here's how the code looks like:
>
> 1) Definition of the handler,  in model.py, before the Root
> controller:
>
> def general_except_handler(self,tg_exceptions=None,**kw):
>     log.error(u'*'+str(datetime.datetime.now())+u'* '+str
> (request.path) + u" Exception: " +  unicode(str
> (tg_exceptions),'latin'))
>     flash(u"exception::Exception: " + unicode(str
> (tg_exceptions),'latin'))
>     redirect('/')
>     return dict()
>
> 2) Definition, just below the handler, of the catching expression
>
> catch_excep_expr="isinstance(tg_exceptions, (KeyError,TypeError))"
>
>
> 3) I then use it for the controllers with exception_handler decorator
>
>     @expose(template="resyweb.templates.generic_form_display")
>     @exception_handler(general_except_handler,catch_excep_expr)
>     @identity.require(identity.in_group("admin"))
>     def edit_reviewer(self,**kw):
>
>
> It works fine but when I try to include something like SQLAlchemyError
> (previously imported with
>
> from sqlalchemy.exceptions import SQLAlchemyError ), I cannot start
> the application:
>
> ...
>  in Root
>     @identity.require(identity.in_group("admin"))
>   File "c:\python25\lib\site-packages\TurboGears-1.1-py2.5.egg
> \turbogears\errorh
> andling.py", line 133, in register
>     dispatch_error_adaptor(handler or func))
>   File "C:\Python25\lib\site-packages\decoratortools-1.7-py2.5.egg\peak
> \util\dec
> orators.py", line 601, in do_decorate
>   File "build\bdist.win32\egg\peak\rules\core.py", line 197, in
> callback
>   File "build\bdist.win32\egg\peak\rules\core.py", line 190, in
> register_for_cla
> ss
>   File "build\bdist.win32\egg\peak\rules\core.py", line 65, in
> parse_rule
>   File "build\bdist.win32\egg\peak\rules\core.py", line 153, in
> __call__
>   File "build\bdist.win32\egg\peak\rules\predicates.py", line 517, in
> _parse_str
> ing
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 424, in
> parse_exp
> r
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 51, in
> com_binary
>
>   File "build\bdist.win32\egg\peak\rules\predicates.py", line 189, in
> And
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 217, in
> atom
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 51, in
> com_binary
>
>   File "build\bdist.win32\egg\peak\rules\predicates.py", line 189, in
> And
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 217, in
> atom
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 178, in
> power
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 284, in
> com_call_
> function
>   File "build\bdist.win32\egg\peak\rules\predicates.py", line 199, in
> CallFunc
>   File "build\bdist.win32\egg\peak\rules\predicates.py", line 233, in
> apply_meta
>
>   File "build\bdist.win32\egg\peak\rules\predicates.py", line 213, in
> parse
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 217, in
> atom
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 356, in
> testlist_
> gexp
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 51, in
> com_binary
>
>   File "build\bdist.win32\egg\peak\rules\codegen.py", line 428, in
> method
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 419, in
> build
>   File "build\bdist.win32\egg\peak\rules\ast_builder.py", line 10, in
> <lambda>
>   File "build\bdist.win32\egg\peak\rules\codegen.py", line 347, in
> Name
> NameError: SQLAlchemyError
>
>
> Would anyone know how to find a solution for this problem, or maybe
> another technique for catching application-wide database exceptions?

I *think* this is because you need to have the name SQLAlchemy defined in the 
module you define the handler in. So do you import it in your controller 
file?

Diez

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to