satchmo_utils.thumbnail.utils confuses URLs with file paths

Create issue
Issue #1101 resolved
Former user created an issue

All around the place the module treats ImageFileField.path as an URL while in fact it is a filesystem storage path. This can result in OSError exceptions depending on your MEDIA_ROOT and MEDIA_URL configuration.

I will attach a path that fixes a tiny part of the problem that breaks the store for my customer. The rest of the code is still wrong, just does not cause exceptions so.

Comments (7)

  1. Chris Moffitt repo owner

    When I apply this patch, I get paths like this in the db: ./images/productimage-picture-neat-book-2.png

    Which in turn, causes my url to look like this: <img width="280" height="108" src="/static/./images/productimage-picture-neat-book-2_png_280x280_q85.jpg">

    This does work but seems a bit messy. I'm hesitant to make changes until we're sure it's 100% backwards compatible.

  2. Patryk Zawadzki

    I'm somewhat surprised to see a dot there. Could you check what path is passed to the rename_by_field in your testing environment? The function should preserve whatever prefix was passed in and Django always stores relative paths in DB. Here it gets "images/foo.jpg" and returns "images/klass-slug.jpg".

  3. Chris Moffitt repo owner

    In my thumbnail/field.py file, I added the following debugging:

    if self.name_field:
        field = getattr(instance, self.name_field)
        print "Path =%s" % image.path
        print "Name = %s" % image.name
        image = rename_by_field(image.name, '%s-%s-%s' \
                                            % (instance.__class__.__name__,
                                               self.name,
                                               field
                                               )
                                            )
    
    

    Here's the output I get:

    Path =/home/chris/src/demostores/simplestore/static/images/magic-pony-django-wallpaper.png
    Name = ./images/magic-pony-django-wallpaper.png
    

    Here's what my MEDIA_ROOT is:

    MEDIA_ROOT = os.path.join(DIRNAME, 'static/')

    I did find if I wrap do a os.path.normpath(image.name) it gets rid of the leading .

    Maybe it's a windows/linux issue.

  4. Chris Moffitt repo owner

    I wrapped the calls in os.path.normpath and it fixes the issue for me. I suspect this will also help other people too so it should be a good fix.

    Please test it out in your scenario and let me know if you see any more anomalies.

    Closing out with commit a81e18f8e5a3

  5. Log in to comment