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

When using s3 boto storage, path gets prepended to the filename twice #50

Open
lsemel opened this issue Mar 11, 2017 · 6 comments
Open
Assignees
Labels

Comments

@lsemel
Copy link

lsemel commented Mar 11, 2017

The value of SITEMAP_ROOT_DIR gets prepended to the filename twice. I had do use a custom storage to avoid this happening:

class S3SitemapStorage(S3BotoStorage):
    def __init__(self, *args, **kwargs):
        super(S3SitemapStorage, self).__init__(*args, **kwargs)
        self.location = ''
@digitaltommy
Copy link

Used an alteration of the above to fix this for the normal storage method.

Add to settings.py

STATICSITEMAPS_STORAGE = 'myproject.sitemaps.SitemapStorage'

Add to myproject/sitemaps.py

from django.core.files.storage import FileSystemStorage

class SitemapStorage(FileSystemStorage):
    def __init__(self, *args, **kwargs):
        super(SitemapStorage, self).__init__(*args, **kwargs)
        self.location = ''

As @lsemel says, this fixes the duplication of a custom SITEMAP_ROOT_DIR

@xaralis
Copy link
Owner

xaralis commented Nov 6, 2017

@digitaltommy Can you make a pull request out of it? It would be appreciated. Thx

@digitaltommy
Copy link

@xaralis sorry just seen this comment - do these pull requests need doing still?

@puzzlet
Copy link

puzzlet commented Sep 19, 2018

It's because SitemapGenerator.storage is initialized with location=conf.ROOT_DIR (5ede702#diff-3d35d9fe93e9b30725df9b15374bea77R27)

-        storage = _lazy_load(conf.STORAGE_CLASS)()
+        self.storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR)

and S3 storage prepends self.location to every path you want to access. (https://github.com/jschneier/django-storages/blob/1.7.1/storages/backends/s3boto.py#L363)

            return safe_join(self.location, name)

Before fixing it, we should find out the original intent of location=conf.ROOT_DIR in the first place. @xaralis

@xaralis
Copy link
Owner

xaralis commented Sep 22, 2018

@puzzlet Correct. I've reviewed the code and don't see any specific reason why this line (self.storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR)) should have location argument in the call. Simply beacuse when writing using the storage, full path is provided too.

It's probably some old thing that noone noticed. It should be safe to remove.

@bashu
Copy link

bashu commented Jun 8, 2019

still not fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants