pyrollbar icon indicating copy to clipboard operation
pyrollbar copied to clipboard

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

Open lmmentel opened this issue 5 years ago • 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?

lmmentel avatar Aug 02 '20 15:08 lmmentel

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)

mattyg avatar Mar 29 '21 17:03 mattyg

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

lmmentel avatar Apr 04 '21 08:04 lmmentel