[Answer]-How to get raven to report Django runscript exceptions to Sentry?

1👍

As of version 5.3.1 of raven-python it should correctly patch Django’s BaseCommand.execute, which effectively will handle errors in these commands (unless that parent call is never made).

0👍

For those out there that:

  1. still have an issue of raven not patching itself for django management commands correctly

  2. have Django==1.6.11

  3. haven raven==5.12.0

I have found a fix that works for me.

The problem seems to be that raven is not patching BaseCommand.execute by the time it is called by Django. So to fix that, I make sure BaseCommand.execute is patched right away. I’ve updated my manage.py file to include the following lines:

from raven.contrib.django.management import patch_cli_runner
patch_cli_runner()

My final manage.py file looks like this:

#!/usr/bin/env python
from os.path import abspath
from os.path import dirname
import os
import sys

if __name__ == "__main__":
# add the ../ directory to the os path, so that we can find
# app.settings below
sys.path.insert(0, os.path.abspath(os.path.join(dirname(abspath(__file__)), '..')))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

from django.core.management import execute_from_command_line
from raven.contrib.django.management import patch_cli_runner
patch_cli_runner()

execute_from_command_line(sys.argv)
👤Paul

Leave a comment