getsentry / raven-python

Raven is the legacy Python client for Sentry (getsentry.com) — replaced by sentry-python
https://sentry.io
BSD 3-Clause "New" or "Revised" License
1.68k stars 658 forks source link

Failed to import client #1034

Closed mikellykels closed 7 years ago

mikellykels commented 7 years ago

From Zendesk: https://sentry.zendesk.com/agent/tickets/7308

We use raven==6.0.0 along with uWSGI app server to track errors in our Django application. Lately we've been seeing this type of tracebacks

[2017-06-30 12:46:26,307: ERROR/Worker-2] Failed to import client: <raven.base.Client object at 0x7fbae5a97e90> 
Traceback (most recent call last): 
File "/srv/python_envs/orbis/local/lib/python2.7/site-packages/raven/contrib/django/models.py", line 127, in get_client 
Client = import_string(client) 
File "/srv/python_envs/orbis/local/lib/python2.7/site-packages/raven/utils/imports.py", line 15, in import_string 
module = __import__(module_name, {}, {}, [class_name], 0) 
ImportError: No module named <raven.base 

Raven is imported as follows in our settings

if ENABLE_SENTRY: 
INSTALLED_APPS += ( 
'raven.contrib.django.raven_compat', 
) 
from sentry_config import RAVEN_CONFIG 
RAVEN_CONFIG['dsn'] = SENTRY_DSN 
SENTRY_CLIENT = Client(SENTRY_DSN)

CC @ashwoods

ashwoods commented 7 years ago

Afaik, current versions expect a dotted path to the Client class, instead of an instance of the class: https://docs.sentry.io/clients/python/integrations/django/#additional-settings

shahkushan1 commented 7 years ago

Hi @ashwoods,

I had raised the ticket and forgot to mention the contents of the module sentry_config mentioned in the code snippet above. Its contents posted below.

import os
import raven

RAVEN_CONFIG = {
    'dsn': None,
    # If you are using git, you can also automatically configure the
    # release based on the git info.
    'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
}

Additionally, the variable SENTRY_DSN is set to None in the default environments but over-ridden for the ones where we enable Sentry logging.

Not sure if this helps but we use uWSGI enabled with master, lazy-apps, enable-threads and single-interpreter

I checked the Additional Settings section of the docs you mentioned and had a couple of questions -

  1. Isn't this setting (mentioning the dotted path of the client class) optional as it seems so from the docs?
  2. Since I've already added raven.contrib.django.raven_compat to the installed apps wouldn't raven load the appropriate client from that module?
  3. Is this additional configuration a breaking change introduced in raven-python v6.1?

Let me know if you need additional info

ashwoods commented 7 years ago

I think the error comes from this in your settings:

SENTRY_CLIENT = Client(SENTRY_DSN)

should be empty or if using a custom client a dotted path to the client class.

I'm not sure if this was a breaking change.

ashwoods commented 7 years ago

I'm assuming this is resolved. Feel free to reopen if not the case.