raven-python icon indicating copy to clipboard operation
raven-python copied to clipboard

Django logs shell exceptions (with Django > 2.0)

Open mjtamlyn opened this issue 7 years ago • 12 comments

I'm not completely sure whether this is a change in Django or in Raven.

I've started seeing typos in the manage.py shell log to Sentry since I upgraded to django 2.0, raven 6.4.0 and Python 3.6. I've come up with a hacky work around, but it did clarify that there's no easy way to disable the sentry client that I could find documented.

Is there any change at this end which might have caused this?

mjtamlyn avatar Jan 09 '18 17:01 mjtamlyn

Hi marc! Can't think of any change, my guess is this is on the django end. Which django version exactly are you using? The only recent changes I see after a quick view is the usage of contextlib.supress

ashwoods avatar Jan 09 '18 19:01 ashwoods

And the revert to try-except

ashwoods avatar Jan 09 '18 19:01 ashwoods

$ python --version
Python 3.6.3
$ django-admin --version
2.0.1

I didn't see this behaviour on Django 1.11.X with Python 2.7.

I'm using a settings.LOGGING config to connect Sentry - https://gist.github.com/mjtamlyn/f640dfac2a4f4a2568f2ca13ba178390

I've also got 'raven.contrib.django.raven_compat' in my INSTALLED_APPS

mjtamlyn avatar Jan 10 '18 09:01 mjtamlyn

Hey,

I am using python 3.6.3 with django 1.11.5 and raven 6.2.1.

Heaving the same problem. Everytime someone misspells something in the shell we receive the error in sentry. @mjtamlyn Can you share you hacky solution?

Ivaylo-Bachvarov avatar Mar 19 '18 19:03 Ivaylo-Bachvarov

Haven't managed to find a good one unfortunately. I think there's some default raven logging to catch all fatal errors now, or Django has started catching shell errors and reporting them (although I can't find any code for the latter).

mjtamlyn avatar Mar 20 '18 10:03 mjtamlyn

I'm having this problem with Django 1.11.x, Raven 6.3.0 and Python 3.6.3. The same thing but with Python 3.5 doesn't seem to show the error. Setups running on Raven 5.X and Python 2.7 do not have this issue.

dbarbeau avatar Apr 18 '18 16:04 dbarbeau

I'm having this problem too, with Python 3.4.7, Django 1.10.4, and Raven 6.5.0.

I saw that when in ./manage.py shell, __name__ == 'builtins', so I tried updating my Django settings' LOGGING to have the 'builtins' logger only handled by console, but it still goes to Sentry.

hjkelly avatar May 11 '18 20:05 hjkelly

We are also having this problem with Python 3.6 and Django 1.11

It's an issue that prevents us form directly hooking Sentry directly to alert systems.

tobami avatar Jun 05 '18 10:06 tobami

Also having the issue where shell errors are showing in sentry, which is something that did not used to happen. Django==1.11.9 raven==6.6.0

iyawnis avatar Jun 07 '18 08:06 iyawnis

I think I've tracked this down to the (good!) change that happened between 6.0.0 and 6.1.0:

fix registration of hooks for Django

PR: https://github.com/getsentry/raven-python/pull/966

Original issue: https://github.com/getsentry/raven-python/issues/884

Since install_sys_hook is working correctly, exceptions raised within a manage.py|django-admin.py session are handled by Sentry.

Here is a basic workaround I've settled on (YMMV):

# in settings.py
import sys
SHELL = "shell" in sys.argv
...
RAVEN_CONFIG = {
    "ignore_exceptions": ("*") if SHELL else ()
}

In should_capture, the wildcard"*" will match any exception.

Other manage.py commands that don't have a "shell" argument will continue to send exceptions to Sentry.

jacobwegner avatar Jul 20 '18 20:07 jacobwegner

I can confirm that the RAVEN_CONFIG described by @jacobwegner works well. Many thanks!

tobami avatar Aug 05 '18 11:08 tobami

@jacobwegner it still works (thanks!), but I think in your solution you meant ("*",) instead of ("*")?

rowanseymour avatar Aug 14 '18 13:08 rowanseymour