0

Django documentation says:

When DEBUG is False, Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (HTTP status code 500).

But does this includes django admin site? And if not, how can I enable such reporting?

I'm asking this because when I intensionally rise an Exception at ModelAdmin subclass I receive no email.

On the other hand I tried to send manually and it works fine.

$ ./manage.py shell
>>> from django.core.mail import EmailMessage
>>> email = EmailMessage('Hello', 'World', to=['email@example.com'])
>>> email.send()

UPDATE: Also Django does sends crash reports when exception rises at API part of application (driven by piston).

Any help is much appreciated.

z4y4ts
  • 2,535
  • 4
  • 21
  • 24
  • Doesn't exactly answer your question but check out django-sentry (http://readthedocs.org/docs/sentry/en/latest/index.html). It's from the team behind Disqus, and has become an absolutely indispensable debugging tool for me. – Chris Pratt Nov 03 '11 at 15:33
  • Can you try raising an exception in your app (not the admin one)? Can you receive such email? – Jakub Gocławski Nov 03 '11 at 15:35
  • @ChrisPratt django-sentry might be an option eventually. But it seems to me like overkill for now. Anyway thanks for your comment. – z4y4ts Nov 03 '11 at 15:54
  • @JakubGocławski yes, I can receive such email. Just tested that. – z4y4ts Nov 03 '11 at 15:55
  • Can you show us the code you are using to raise the exception in the `ModelAdmin` subclass. – Alasdair Nov 03 '11 at 16:07
  • @Alasdair It's as simple as `raise Exception`. Nothing sophisticated. – z4y4ts Nov 03 '11 at 16:21
  • I meant *where* is `raise Exception` line. I've updated my answer with an example. – Alasdair Nov 03 '11 at 16:30

1 Answers1

0

There is nothing special about the admin site in this instance. Django will send you an email when an admin view raises an unhandled exception.

Troubleshooting idea 1

Have you tested whether you receive an email for a non-admin view? Could it be a permissions issue? The webserver might be running as a different user than when you test emailing from the shell.

Troubleshooting idea 2

Where in the ModelAdmin are you raising the exception?

The following example will not work, because the exception is raised when the ModelAdmin class is defined, not when the request is processed.

class MyModelAdmin(ModelAdmin):
    raise Exception

Instead, raise the exception in a method. You should get an email for the following model, if you go to it's change view url (e.g /admin/app/mymodel/)

class MyModelAdmin(ModelAdmin):
    def get_queryset(self, request, queryset):
        raise Exception
Alasdair
  • 298,606
  • 55
  • 578
  • 516