rollbar/pyrollbar

Getting 'PosixPath' object has no attribute 'lower' with django

lmmentel opened this issue · 2 comments

I configured integration with django following the docs, however when an exception is raise somewhere in the app I get in addition

django_1  | During handling of the above exception, another exception occurred:
django_1  | 
django_1  | Traceback (most recent call last):
django_1  |   File "/usr/local/lib/python3.8/site-packages/rollbar/__init__.py", line 944, in _add_locals_data
django_1  |     if arginfo.locals and _check_add_locals(cur_frame, frame_num, num_frames):
django_1  |   File "/usr/local/lib/python3.8/site-packages/rollbar/__init__.py", line 1047, in _check_add_locals
django_1  |     ('root' in SETTINGS and (frame.get('filename') or '').lower().startswith((SETTINGS['root'] or '').lower()))))
django_1  | AttributeError: 'PosixPath' object has no attribute 'lower'

Is there a way to get rid of that?

The Rollbar library is expecting a str for the configuration variable "root", but django's settings.BASE_DIR is a PosixPath.

Modify your rollbar settings in settings.py to cast BASE_DIR to a str:

import rollbar

ROLLBAR = {
    "access_token": "12345"
    "environment": "development" if DEBUG else "production",
    "root": str(BASE_DIR)
}

rollbar.init(**ROLLBAR)

Got it, thanks for the response. Might be worth updating rollbar config at some point to accept a PosixPath since django switched to Paths in settings.py as default since 3.x