Closed tomkins closed 2 months ago
Transferred this issue from Wagtail, as whilst we can avoid the issue in Wagtail, there's still a bug in Willow to fix.
The root cause is in this block: https://github.com/wagtail/Willow/blob/7e49ca06dc5211a3e85bfc89314ba8ae3914e854/willow/image.py#L150-L173
The if
doesn't have an else
case, and so if an unexpected type is passed, file_path
never gets defined.
The solution will either be to attempt to read whatever object we get into a SpooledTemporaryFile
, or explicitly raise a type error.
Issue Summary
Currently when you've got an optimizer enabled in
WILLOW_OPTIMIZERS
, and use the Image URL Generator, it'll come up with a 500:Slightly obscure (not sure how many people actually the combination of Willow optimizers and the dynamic image serve view!).
Steps to Reproduce
Install optipng if you don't have it already (
brew install optipng
)Add
ServeView
into your URL config (see https://docs.wagtail.org/en/v6.1.2/advanced_topics/images/image_serve_view.html#setup)Edit your settings file, add:
WILLOW_OPTIMIZERS = "optipng"
Upload a PNG into Wagtail images (eg. https://github.com/wagtail/wagtail/blob/d44808ac532a96c60b16377fbb25d29d7eae704c/docs/logo.png)
Go to the edit image view, click on URL Generator on the right hand side
Page loads, but the image fails to appear and generates the above 500
I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes
Technical details
Working on this
Pull request coming shortly!