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

gcloud raises NotFound exception on self.storage.url(self.name) #463

Closed
sww314 opened this issue Mar 5, 2018 · 4 comments
Closed

gcloud raises NotFound exception on self.storage.url(self.name) #463

sww314 opened this issue Mar 5, 2018 · 4 comments
Labels

Comments

@sww314
Copy link
Contributor

sww314 commented Mar 5, 2018

I am serializing an ImageFileField with Django RestFramework. If the file does not exist it raises NotFound().

I am not sure how the other network storage layers work, but this is not how the file storage in Django core works it will simply return a URL.

I suggest the code be changed to return the URL without checking to see if the blob exists.

@zisk0
Copy link

zisk0 commented Mar 7, 2018

Hi!

We have been hitting the same problem. When URL is built, _get_blob() is called and raises a NotFound exception if file does not exists. As a workaround, we wrote a CustomImageField that builds the URL in case the file doesn't exist, but _get_blob() is always executed. I also realized it introduces some overhead when listing objects with images. Is it possible that the reason is the execution of _get_blob() connecting to GCS?

@sww314
Copy link
Contributor Author

sww314 commented Mar 7, 2018

@zisk0 Yes. get_blob connects to GCS. I do not think it should unless you need the file retrieved for writes, reads, etc.
Currently, it will make a call to verify the bucket exists as well (making it slower).

@zisk0
Copy link

zisk0 commented Mar 7, 2018

AFAIK it is to obtain the public_url of the blob. We were working to control this URL using:

 def url(self, name):
    # Preserve the trailing slash after normalizing the path.
    name = self._normalize_name(clean_name(name))
    if self.base_url:
        return self.base_url + name
    else:
        blob = self._get_blob(self._encode_name(name))
        return blob.public_url

Where self.base_url is a setting:

class GoogleCloudStorage(Storage):
// ...
base_url = setting('GS_CDN_BASE_URL', None)

This is also a workaround for #385. Now load speed has been improved.

@jschneier
Copy link
Owner

All of this discussion is now ongoing in #491.

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

No branches or pull requests

3 participants