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

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

Closed
The-Judge opened this issue Apr 30, 2024 · 5 comments · Fixed by #1403
Closed

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

The-Judge opened this issue Apr 30, 2024 · 5 comments · Fixed by #1403

Comments

@The-Judge
Copy link

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
Copy link
Owner

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
Copy link
Author

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

@Frodothedwarf
Copy link
Contributor

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
Copy link
Contributor

@jschneier fixed this in #1403

@ch0wm3in
Copy link

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

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