Skip to content

Conversation

ljluestc
Copy link

Made LibCloudStorage.url() in storages/backends/apache_libcloud.py idempotent by avoiding unnecessary API calls for non-CDN providers (e.g., Google Cloud Storage) and handling empty paths (e.g., {% static '' %}), addressing issue #133. Fixed storages.utils.clean_name to preserve empty strings, resolving invalid URLs in Google Cloud Storage (issue #132). The url() method now returns the base bucket URL for empty paths without querying the storage API and skips _get_object for drivers without get_object_cdn_url. Tests verify behavior across providers, including GCS and S3, and empty path handling. Documentation and changelog updated.

Key Changes

  • Updated LibCloudStorage.url():

    • Handles empty name by returning base bucket URL (e.g., https://storage.googleapis.com/test-bucket/) without API calls.
    • Checks for get_object_cdn_url before calling _get_object, avoiding unnecessary API requests for non-CDN drivers.
    • Returns None for nonexistent objects in CDN mode.
  • Fixed storages.utils.clean_name:

  • Added tests in tests/test_apache_libcloud.py:

    • Verified base URL generation for empty paths without API calls (GCS, S3).
    • Tested URL construction for existing and nonexistent objects.
    • Confirmed CDN-enabled driver behavior.
    • Ensured clean_name('') returns empty string.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant