jschneier / django-storages

https://django-storages.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.7k stars 847 forks source link

`ValueError` when running `manage.py collectstatic --clear` #1392

Closed The-Judge closed 1 month ago

The-Judge commented 2 months ago

Following the manual to use django-storages with Azure and staticfiles storage, I end up with this Django configuration:

STORAGES["staticfiles"] = {
            "BACKEND": "storages.backends.azure_storage.AzureStorage",
            "OPTIONS": {
                "account_name": os.getenv("AZURE_SA_NAME", None),
                "azure_container": os.getenv("AZURE_CONTAINER_NAME_STATIC", "static"),
                "overwrite_files": True if os.getenv("AZURE_OVERWRITE_FILES", "False").capitalize() == "True" else False,
                "account_key": os.getenv("AZURE_ACCOUNT_KEY", None),
            }
        }

Running the manage.py task collectstatic works fine and stores the static files in the Azure Storage Account container static. When running the task with --clear, this error is raised:

Traceback (most recent call last):
  File "/Users/marichter/Nextcloud/Dokumente/Entwicklung/darts-central/dc-django/./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
    collected = self.collect()
                ^^^^^^^^^^^^^^
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 117, in collect
    self.clear_dir("")
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 251, in clear_dir
    if not self.storage.exists(path):
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/storages/backends/azure_storage.py", line 271, in exists
    blob_client = self.client.get_blob_client(self._get_valid_path(name))
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/storages/backends/azure_storage.py", line 255, in _get_valid_path
    return _get_valid_path(self._normalize_name(clean_name(name)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/marichter/.local/share/virtualenvs/dc-django-Jq1XImY9/lib/python3.11/site-packages/storages/backends/azure_storage.py", line 106, in _get_valid_path
    raise ValueError("File name must contain one or more printable characters")
ValueError: File name must contain one or more printable character
jschneier commented 2 months ago

This is a bug in the backend related to the fact that the root element is the bucket and not a path. We need to add logic similar to Google Cloud. Up for it?

The-Judge commented 2 months ago

I don't understand a single word from all that. I just experienced the shown behavior and reported it.

Frodothedwarf commented 2 months ago

This is a bug in the backend related to the fact that the root element is the bucket and not a path. We need to add logic similar to Google Cloud. Up for it?

I will make a pull request adding this logic. This is a very annyoning bug for anyone dependent on Azure storage.

Frodothedwarf commented 2 months ago

@jschneier fixed this in https://github.com/jschneier/django-storages/pull/1403

ch0wm3in commented 2 months ago

@jschneier Any plans for merging the fix by @Frodothedwarf ?