Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Django signal handlers not fail silently when an exception is encountered in the signal handler?

How do I make Django signal handlers not fail silently when an exception is encountered in the handler?

Is there a place where all these errors are logged while using development server?

Why do django signal handlers fail silently anyway? Isn't it against one of the lines in Zen of Python?

Zen of Python clearly states...

Errors should never pass silently.

It makes them a nightmare to debug. All you can see is that the signal is not getting fired...

I found this question but the answer is useless to me as it is very specific to the question (answer suggests using pyflakes, I already use pydev which does satisfactory static analysis)

like image 491
Optimus Avatar asked Jan 23 '13 13:01

Optimus


People also ask

How do you call a signal in Django?

There are two ways to send signals in Django. To send a signal, call either Signal. send() (all built-in signals use this) or Signal. send_robust() .

Are Django signals asynchronous?

To answer directly: No. It's sync.

What is the use of the Post_delete signal in Django?

Django Signals - post_delete()To notify another part of the application after the delete event of an object happens, you can use the post_delete signal.


1 Answers

Yes, errors should never fail silently

Yes, I think like you: errors should never fail silently

Built in signals don't fail silently

Django's built in signals don't fail silently because they use send()

Only send_robust() ignores exceptions

Docs from send_robust()

send_robust() catches all errors derived from Python’s Exception class, and ensures all receivers are notified of the signal. If an error occurs, the error instance is returned in the tuple pair for the receiver that raised the error.

Conclusion

Since django doesn't use send_robust() please investigate where it gets called. I guess it is in your source code, or in the code of a third party app.

like image 134
guettli Avatar answered Sep 19 '22 12:09

guettli