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

Incompatible with Pathlib from v4.0 #192

Closed
browniebroke opened this issue Aug 13, 2018 · 4 comments
Closed

Incompatible with Pathlib from v4.0 #192

browniebroke opened this issue Aug 13, 2018 · 4 comments

Comments

@browniebroke
Copy link
Contributor

browniebroke commented Aug 13, 2018

Python 3.4 added an awesome tool for working with path, Pathlib, which has a nicer API than os.path. We've set up our Django project as follow:

from pathlib import Path

BASE_DIR = (Path(__file__) / '..' / '..' / '..' / '..').resolve()
STATICFILES_DIRS = [
    BASE_DIR / 'static-build',
]
STATIC_ROOT = BASE_DIR / 'staticfiles'

Some changes added in v4.0 are now relying on str.rstrip when processing files to account for trailing slash (I assume).

However, this is breaking our project as pathlib doesn't have the rstrip() method:

AttributeError: 'PosixPath' object has no attribute 'rstrip'

I'll try to send a patch to fix this.

@evansd
Copy link
Owner

evansd commented Aug 13, 2018

Thanks for reporting this. I guess we just need to cast paths to strings in the appropriate places.

@laixintao
Copy link

Same issue here, our previous whitenoise version is 3.3.1, it works fine. But when we upgrade to v4.0, a testcase failed.

----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builds/isre/takachiho/noise_reductor/tests/test_remark.py", line 17, in test_marking_noise_analysis
    response = self.client.get(self.url+'?is_noise=true')
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 517, in get
    response = super().get(path, data=data, secure=secure, **extra)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 332, in get
    return self.generic('GET', path, secure=secure, **r)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 404, in generic
    return self.request(**r)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 467, in request
    response = self.handler(environ)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 125, in __call__
    self.load_middleware()
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 39, in load_middleware
    mw_instance = middleware(handler)
  File "/usr/local/lib/python3.6/site-packages/whitenoise/middleware.py", line 40, in __init__
    self.add_files(self.static_root, prefix=self.static_prefix)
  File "/usr/local/lib/python3.6/site-packages/whitenoise/base.py", line 92, in add_files
    root = root.rstrip(os.path.sep) + os.path.sep
AttributeError: 'PosixPath' object has no attribute 'rstrip'

Our settings is exactly same as @browniebroke

@laixintao
Copy link

Current we change our STATIC_ROOT to this:

STATIC_ROOT = str(BASE_DIR / 'staticfiles')

@laixintao
Copy link

Thanks!

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

No branches or pull requests

3 participants