Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lmmentel opened this issue Aug 2, 2020 · 2 comments · May be fixed by #450
Open

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

lmmentel opened this issue Aug 2, 2020 · 2 comments · May be fixed by #450

Comments

@lmmentel
Copy link

lmmentel commented Aug 2, 2020

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?

@mattyg
Copy link

mattyg commented Mar 29, 2021

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)

@lmmentel
Copy link
Author

lmmentel commented Apr 4, 2021

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

dragon-dxw added a commit to nationalarchives/ds-caselaw-public-ui that referenced this issue Aug 24, 2023
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/rollbar/__init__.py", line 1026, in _add_locals_data
if arginfo.locals and _check_add_locals(cur_frame, frame_num, num_frames):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/rollbar/__init__.py", line 1129, in _check_add_locals
('root' in SETTINGS and (frame.get('filename') or '').lower().startswith((SETTINGS['root'] or '').lower()))))
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'lower'

rollbar/pyrollbar#345 suggests this is caused by rollbar reciving a PosixPath not a string, so we coerce it before passing it to the config.
dragon-dxw added a commit to nationalarchives/ds-caselaw-public-ui that referenced this issue Aug 24, 2023
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/rollbar/__init__.py", line 1026, in _add_locals_data
if arginfo.locals and _check_add_locals(cur_frame, frame_num, num_frames):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/rollbar/__init__.py", line 1129, in _check_add_locals
('root' in SETTINGS and (frame.get('filename') or '').lower().startswith((SETTINGS['root'] or '').lower()))))
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'lower'

rollbar/pyrollbar#345 suggests this is caused by rollbar reciving a PosixPath not a string, so we coerce it before passing it to the config.
@singingwolfboy singingwolfboy linked a pull request May 17, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants