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.

Hi, first of all nice library, i wanna ask if it’s possible to retrieve generated file size in some place, i have a signal to compute and save my image size but i can’t find the variations size.

def compute_size(instance, raw, **kwargs):
    if hasattr(instance, 'image') and instance.image and not raw:  # Required check for tests and fixtures
        user = instance.exercise.created_by if isinstance(instance, ExerciseImage) else instance.comment.user
        total_size = instance.image.size
        if hasattr(instance.image, 'variations'):  # Never runs
            for variation in instance.image.variations:
                total_size += variation.size

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
codingjoecommented, May 14, 2018

I honestly never tried that. Mostly because the variation size is kind of specified is it not? At least it’s max bounds. that being said, you don’t have access to the variations at this point, because they did not exist when class was created. Mostly because you are creating a new object. You would need to call set_variations manually. It’s usually called in contribute_to_class which in tern is called when a Django model is constructed. As I said, not in this particular case.

I hope that helps you, let me know if I can be of more help.

0reactions
iagocanalejascommented, May 1, 2018

Sorry, same error

@receiver(post_save, sender=ModelName)
def compute_size(instance, raw, **kwargs):
    if hasattr(instance, 'image') and instance.image and not raw:  # Required check for tests and fixtures
        total_size = instance.image.size
        if hasattr(instance.image, 'field') and hasattr(instance.image.field, 'variations'):
            for variation, _ in instance.image.field.variations.items():
                total_size += getattr(instance.image, variation).size

I also try debugging it but the object only contains errors like:

 thumbnail = {ImageFieldFile} path/image.png
	_committed = {bool} True
	closed = {bool} True
	_file = {NoneType} None
	 file = {str} 'Traceback (most recent call last):\n  File "C:\\Users\\Canalejas\\AppData\\Local\\JetBrains\\Toolbox\\apps\\PyCharm-P\\ch-0\\181.4203.547\\helpers\\pydev\\_pydevd_bundle\\pydevd_resolver.py", line 166, in _getPyDictionary\n    attr = getattr(var, n)\n  File 
	size = {str} 'Traceback (most recent call last):\n  File "C:\\Users\\Canalejas\\AppData\\Local\\JetBrains\\Toolbox\\apps\\PyCharm-P\\ch-0\\181.4203.547\\helpers\\pydev\\_pydevd_bundle\\pydevd_resolver.py", line 166, in _getPyDictionary\n    attr = getattr(var, n)\n  File 

The image is still created even if the signal fail.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File size - Wikipedia
File size is a measure of how much data a computer file contains or, alternately, how much storage it consumes. Typically, file size...
Read more >
What Is The File Size? - Metadata2Go.com
The size of a file is the amount of space it takes up on your hard drive. The File Size is measured in...
Read more >
File Size Calculator - File Size Explained - MindGems
File size calculator will convert file sizes to any units of measure - bits, bytes, kilobytes, megabytes, gigabytes, terabytes, or petabytes.
Read more >
File Sizes and Transfer Speeds - 2BrightSparks
File sizes are measured in Bytes (B), Kilobytes (KB), Megabytes (MB), Gigabytes (GB), Terabytes (TB) and so on. The file sizes can be...
Read more >
What is File Size? - Computer Hope
A file size is the measure of space a file takes up on a storage medium, such as a computer hard drive. File...
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