Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: get_default_storage_root_url() is not returning absolute path from GCS #13346

Open
byronrode opened this issue Jul 7, 2023 · 6 comments

Comments

@byronrode
Copy link

byronrode commented Jul 7, 2023

What are you trying to achieve?

When using GCS_MEDIA_BUCKET_NAME to upload images to GCS, and not using local images, product media URLs in queries should return the get_default_storage_root_url() along with the absolute URL to the image, instead of the thumbnail URLs.

It currently returns the url from shop.domain along with the path/uuid/size URL instead.

Example

{
  shop {
    version
    domain {
      url
      host
      sslEnabled
    }
  }
}

{
  "data": {
    "shop": {
      "version": "3.14.2",
      "domain": {
        "url": "http://testing.com",
        "host": "https://testing.com",
        "sslEnabled": false
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 0,
      "maximumAvailable": 50000
    }
  }
}

Returned URL: http://testing.com/thumbnail/UHJvZHVjdE1lZGlhOjYy/4096/
Expected URL: https://storage.googleapis.com/bucket/path/filename.ext

Running the following in the container shell:

>>> from saleor.core.utils.url import get_default_storage_root_url
>>> print(get_default_storage_root_url())
https://storage.googleapis.com/bucket-name/

Running exportFiles queries return the correct URLs, so this seems to only be affecting products.

We do not use storefront at all, as we have built our own frontend, and setting the shop domain to null or '' does not have any effect.

Steps to reproduce the problem

  1. Set GCS_MEDIA_BUCKET_NAME and authenticate to GCS via other envvars
  2. Upload a product or product variant image via the dashboard or playground
  3. Check the edges.node.media.url and edges.node.variants.media.urlin GraphQLproducts` query and it returns the wrong URL
  4. Check the image source in the dashboard
  5. Confirm that the image has in fact been uploaded to Storage Bucket
...
"media": [
  {
    "metafields": {},
    "privateMetafields": {},
    "id": "UHJvZHVjdE1lZGlhOjYy",
    "url": "https://testing.com/thumbnail/UHJvZHVjdE1lZGlhOjYy/4096/"
  }
]
...

What did you expect to happen?

For an absolute URL from GCS to be returned.

Logs

No response

Environment

Bug has existed since at least Saleor version 3.7.2 or 3.12.0

Current Saleor version: 3.14.2
Current Saleor Dashboard version: 3.14.4
OS and version: Docker Containers on Ubuntu 22.04

@byronrode
Copy link
Author

Additionally the following gets the correct URL as well.

>>> from django.core.files.storage import default_storage
>>> print(default_storage.url('https://rs.http3.lol/index.php?q=aHR0cHM6Ly9naXRodWIuY29tL3NhbGVvci9zYWxlb3IvaXNzdWVzL3RodW1ibmFpbA'))
https://storage.googleapis.com/bucket-name/thumbnail

@byronrode
Copy link
Author

If there is an envvar that is required to return the absolute URL, it should be added to the docs but checking various resolvers and settings.py I couldn't seem to find anything that would overwrite that.

@byronrode
Copy link
Author

I have just found the (thumbnails)[https://docs.saleor.io/docs/3.x/developer/thumbnails] document, and will try to use the dashboard url for setting the shop domain, and see if that assists with generation, but for this to be truly headless, there should be an easier way to do this.

@byronrode
Copy link
Author

Okay that, didn't work either, as we are using a reverse proxy (nginx), and we have our own SSL termination, so we cannot enforce SSL on Saleor side. Thumbnail generation should be allowed to be toggled by ENVVAR

@byronrode
Copy link
Author

Running the following generates the URL:

>>> from saleor.thumbnail.views import handle_thumbnail
handle_thumbnail(None, instance_id='UHJvZHVjdE1lZGlhOjYy', size='4096')

which returns the URL and then updates the queries.

So, either, we have to override the shop URLs to allow https URLs without needing to enable SSL which should generate the images by default once they are loaded in the dashboard, or there should be a way to enforce that handle_thumbnail runs on every upload if there is an ENVVAR set.

@timuric timuric changed the title Bug: Bug: get_default_storage_root_url() is not returning absolute path from GCS Jul 7, 2023
@byronrode
Copy link
Author

Another bit of investigation, and what I guess it the actual bug:

Using the API url, and the thumbnail path https://API_URL/thumbnail/UHJvZHVjdE1lZGlhOjYy/4096/ generates the actual media URL, however, we since we don't use the thumbnail field in any of our queries and use media.url and it seems that media URL is not generated unless the handle_thumbnail method is called.

Updated Query response after running the the thumbnail URL above:

"thumbnail": {
    "url": "http://testing/thumbnail/UHJvZHVjdE1lZGlhOjYy/4096/webp/",
    "alt": ""
  },
  "media": [
    {
      "metafields": {},
      "privateMetafields": {},
      "id": "UHJvZHVjdE1lZGlhOjYy",
      "url": "https://storage.googleapis.com/bucket-name/thumbnails/products/imagename_thumbnail_4096.jpeg"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant