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

AttributeError: 'str' object has no attribute '__root__' #197

Closed
JimFawkes opened this issue Aug 8, 2018 · 4 comments
Closed

AttributeError: 'str' object has no attribute '__root__' #197

JimFawkes opened this issue Aug 8, 2018 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@JimFawkes
Copy link

Hi,

I just got an error that I do not understand.

Here is what I did:
In order for django-debug-toolbar (dtb) to work I wanted to add 127.0.0.1 to INTERNAL_IPS. Because I was only trying to check if this causes dtb to work, I did not set this setting via environment variables or the env file.
For some reason this throws an exception which has its root in environ/environ.py", line 730, in __eq__, because dtb calls normpath(path) from posixpath.py in line 333 (see Traceback below).

I do not understand why django-environ is involved in this at all. Can you give me an explanation?
A nother very strange thing is that any other entry in INTERNAL_IPS does not cause this error.
Why is this specific IP causing this error?

Traceback (most recent call last):
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
    response = self.get_response(request)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response
    response = self._middleware_chain(request)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/django/utils/deprecation.py", line 142, in __call__
    response = self.process_response(request, response)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/debug_toolbar/middleware.py", line 132, in process_response
    panel.generate_stats(request, response)
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/debug_toolbar/panels/templates/panel.py", line 220, in generate_stats
    'template_dirs': [normpath(x) for x in template_dirs],
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 333, in normpath
    if path == '':
  File "/Users/username/.ENV/my_project/lib/python2.7/site-packages/environ/environ.py", line 730, in __eq__
    return self.__root__ == other.__root__
AttributeError: 'str' object has no attribute '__root__'

I apreciate any kind of hint as to how to solve this or how to further debug this or any explanation why this is happening.

@dennereed
Copy link

dennereed commented Mar 15, 2019

I'm experiencing the same issue. It crops up when I attempt unit tests. The issue seems to stem from environ.py line 709 in the Path class, __eq__ method,

def __eq__(self, other):
        return self.__root__ == other.__root__

The method raises an AttributeError because other lacks a __root__ method. My best guess is that unittest tries to set path variables and somehow it is passing them in as strings instead of path objects. I modified the function to

    def __eq__(self, other):
        # return self.__root__ == other.__root__
        try:
            return self.__root__ == other.__root__
        except AttributeError:
            return self.__root__ == other

and this resolved the issue for me. Not sure if this is a safe solution or not.

tkdchen pushed a commit to tkdchen/django-environ that referenced this issue Oct 6, 2019
tkdchen pushed a commit to tkdchen/django-environ that referenced this issue Oct 6, 2019
@sergeyklay sergeyklay added the bug Something isn't working label Sep 7, 2021
@gone
Copy link

gone commented Dec 22, 2021

Also got bit by this - fix was updating settings:
from
STATIC_ROOT = root("static")

to

STATIC_ROOT = root.path("static")

@mlissner
Copy link

This looks like a dup or at least is heavily related to #86

@sergeyklay
Copy link
Collaborator

Fixed in develop branch. Feel free to open a new issue if the problem appears again. Thank you for reporting and I'm sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants