Opened 13 years ago
Closed 12 years ago
#18374 closed Cleanup/optimization (fixed)
ImageField not validating due to missing libraries
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
IMHO, it is worth to be mentioned in the documentation that libjpeg
must be available on the system PRIOR to PIL being installed.
Else, validating a form with an ImageField
will fail with corrupt image
error, due to django/forms/fields.py
plays down the Exception in line 592, which most probably is IOError: "decoder jpeg not available"
On a Mac, it can be easily downloaded on
http://ethan.tira-thompson.com/Mac_OS_X_Ports.html
On most Linux distributions, libjpeg-dev
is available in the repositories.
Afterwards, PIL must be re-compiled and -installed in order to let it know about it.
Attachments (1)
Change History (12)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
I also don't believe that our installation documentation has to go into this level of detail, especially since PIL's installer does the right thing.
The ticket also says that Django is masking an exception. Maybe we could improve that part?
comment:3 by , 13 years ago
I can't see how we can be more explicit without confusing the user. The actual exception message is "Upload a valid image. The file you uploaded was either not an image or a corrupted image.
".
The only think I can think of is raising a different error message if DEBUG=True
by telling the developer this might be due to an unavailable decoder?
follow-up: 5 comment:4 by , 13 years ago
django/forms/fields.py
, lines 592 - 596:
except Exception: # Python Imaging Library doesn't recognize it as an image raise ValidationError(self.error_messages['invalid_image']) if hasattr(f, 'seek') and callable(f.seek): f.seek(0) return f
I suggest to put the Exception message into the error if DEBUG=True
.
Otherwise, the developer always has to check the django code to get those details.
So, for instance:
except Exception: # Python Imaging Library doesn't recognize it as an image if settings.DEBUG: raise ValidationError(self.error_messages['invalid_image'], e) raise ValidationError(self.error_messages['invalid_image']) if hasattr(f, 'seek') and callable(f.seek): f.seek(0) return f
comment:5 by , 13 years ago
Of course it'll be
except Exception, e: # Python Imaging Library doesn't recognize it as an image if settings.DEBUG: raise ValidationError(self.error_messages['invalid_image'], e) raise ValidationError(self.error_messages['invalid_image']) if hasattr(f, 'seek') and callable(f.seek): f.seek(0) return f
...
comment:6 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Well, this won't help debug the issue when it happens in production. I'm going to improve the docs a bit.
by , 12 years ago
Attachment: | 18374.diff added |
---|
comment:9 by , 12 years ago
Has patch: | set |
---|
comment:11 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
When installing
PIL
usingsetup.py install
or viapip
you get clear warnings that support for a specific format is not available.IMHO the warning raised by
PIL
's setup nails it but I'd like to hear someone else about that.