You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create products using productBulkCreate and media already uploaded to Saleor.
Important context:
There are two "types" of image URLs returned by Saleor, based on if it was requested previously. When resized image URL was never requested before, it follows format: https://XXX.saleor.cloud/thumbnail/UHJvZHVjdE1lhOjI0NA==/4096/ (no file name and extension)
After the URL was visited (requested) the image is resized and during the next query to the API url follows the format: https://xxx.saleor.cloud/media/thumbnails/products/saleordemoproduct_fd_juice_02_thumbnail_4096.png (file name and extension included).
The bug occurs when the first type of URL is used (no file name or extension)
productBulkCreate is raising the same error as productMediaCreate in the get_oembed_data function, but the error is not wrapped with ValidationError, thus it fails with "Internal Server Error" (example log from Sentry). We should fix the mutation to catch errors from get_oembed_data and transform them to handled ValidationError.
the actual problem here is that our is_image_url function doesn't recognize such URLs https://v314.staging.saleor.cloud/thumbnail/UHJvZHVjdE1lZGlhOjI0NQ==/4096/ as image URL. We could extend this function with a check that tries to match the regex of our thumbnail's view, and if yes treat is as an image.
After internal discussion, here is the proposed solution:
drop the is_image_url function - we shouldn't assume that URL represents an image just by the looks of the URL; instead, we should download the file and check its mime type.
downloading the file and checking the mime type is already done in the validate_image_url, which should be used instead of is_image_url.
fix the handle_thumbnail view to always set the Content-Type header in the redirect responses (we should be able to get mime-type from the image file)
in both mutations productMediaCreate and productBulkCreate, we should allow redirects when fetching the actual image data image_data = HTTPClient.send_request(...)
Extra fix: the handle_thumbnail uses 302 redirect code, but it should be a permanent redirect code, this can be fixed by using HttpResponsePermanentRedirect redirect class.
What are you trying to achieve?
Create products using
productBulkCreate
and media already uploaded to Saleor.Important context:
There are two "types" of image URLs returned by Saleor, based on if it was requested previously. When resized image URL was never requested before, it follows format:
https://XXX.saleor.cloud/thumbnail/UHJvZHVjdE1lhOjI0NA==/4096/
(no file name and extension)After the URL was visited (requested) the image is resized and during the next query to the API url follows the format:
https://xxx.saleor.cloud/media/thumbnails/products/saleordemoproduct_fd_juice_02_thumbnail_4096.png
(file name and extension included).The bug occurs when the first type of URL is used (no file name or extension)
Steps to reproduce the problem
Response:
What did you expect to happen?
Product with media be created
Logs
No response
Environment
Saleor version: 3.14.30
OS and version: …
Tasks
The text was updated successfully, but these errors were encountered: