question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

delete_sized_images() fails with custom upload_to

See original GitHub issue

I have a custom upload_to path:

def file_name(instance, path):
    filename = os.path.basename(path)
    sepFilename = os.path.splitext(filename)
    newFilename = slugify(sepFilename[0]) + sepFilename[1]
    year = str(instance.album.year)
    album_slug = instance.album.slug

    return '/'.join([year, album_slug, newFilename])

#...

class Image(BaseMedia):
    file = VersatileImageField(upload_to=file_name)
    #...

When I run delete_sized_images() the files are not deleted. The problem is the custom path is both appended by get_sized_root_folder() and prepended by sizer_regex.

Example:

def delete_sized_images(self):
    #...
    print(self.get_sized_root_folder()) # __sized__/2015/sd/
    print(self.sizer_regex.pattern)     # 2015/sd/g0043229-(thumbnail|crop)-(\d+)x(\d+)(?:-\d+)?.JPG
    #...

Thank you for your time.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
respondcreatecommented, Jul 29, 2016

Hey @Mortal & @neic

I thought I released this last month but I forgot to upload it to PyPI! This has been fixed in the 1.6 release which you can now install from PyPI:

$ pip install django-versatileimagefield==1.6

Thanks for finding (and patching!) this bug! 😃

0reactions
AlwxSincommented, Mar 20, 2018

I’m not sure, is my bug related to this, but… I have custom upload_to path. But I’m not using subclassed SizedImage. I have only several rendition key sets in settings like this

VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
    'response_image': [
        ('full_size', 'url'),
        ('preview', 'thumbnail__45x45')
    ],
    'comment_image': [
        ('full_size', 'url'),
        ('preview', 'thumbnail__45x45')
    ]
}

And pre-warmer in post_save signal like this

@receiver(post_save, sender=ResponseImage)
@receiver(post_save, sender=CommentImage)
def warm_img(instance, **kwargs) -> None:
    img_warmer = VersatileImageFieldWarmer(
        instance_or_queryset=instance,
        rendition_key_set=instance.RENDITION_KEYSET,
        image_attr='image'
    )
    img_warmer.warm()

instance.RENDITION_KEYSET matches key in settings.

After I read #62 I suggest that my thumbnail images must contain thumbnail word in file name, but they doesn’t. And now I’m not sure, what should I fix. I have no control on thumbnail image file names. Only on original image. Should I subclass ThumbnailImage, redefine it filename_key_regex or filename_key? Or something else?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in custom option file upload on magento 2.3.x
A few weeks ago some clients were uploading pdf files, and when they added to the cart, showed them an error the file...
Read more >
[Magento 2.2.5 - 2.3.x] Upload fails in image uploader #16531
An error is shown: "File validation failed." No image is uploaded. I tried different kind of filetypes. In 2.2.4 and previous versions there...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found