Django-storages[azure]: NotImplementedError: This backend doesn't support absolute paths
I have Django application with celery task that I am trying to run on Azure using the code from below.
The main goal is to read python, yaml and template files when running celery task.
I am getting the following error:
NotImplementedError: This backend doesn't support absolute paths.
I am using django-filer and django-storages[azure] to handle my media files and I use Azure Storage to store all my files.
My model looks like this:
class Mymodel(models.Model):
...
id_config_file = FilerFileField(null=True, blank=True, related_name="spider_config_file", on_delete=models.CASCADE)
yaml_config_file = FilerFileField(null=True, blank=True, related_name="yaml_config_file", on_delete=models.CASCADE)
template_file = FilerFileField(null=True, blank=True, related_name="template_file", on_delete=models.CASCADE)
Below is my celery task:
@shared_task(name="schedule_test")
def schedule_test(id):
id = Mymodel.objects.get(id=id)
id_config_file = id.id_config_file.file
yaml_config_file = id.yaml_config_file.file
template_file = id.template_file.file
id_config_file_path = os.path.join(MEDIA_URL, f"{id_config_file}")
yaml_config_file_path = os.path.join(MEDIA_URL, f"{yaml_config_file}")
template_file_path = os.path.join(MEDIA_URL, f"{template_file}")
spec = importlib.util.spec_from_file_location("id", id_config_file_path)
id_module = importlib.util.module_from_spec(spec)
sys.modules["id"] = id_module
spec.loader.exec_module(id_module)
asyncio.run(id_module.run(
yaml_config_path = yaml_config_file_path,
input_file_path = template_file_path,
task_id = schedule_test.request.id
))
return f"[id: {id}]"
My settings.py contains Azure Storage config variables:
DEFAULT_FILE_STORAGE = 'azure.storage_production.AzureMediaStorage'
AZURE_ACCOUNT_NAME = os.environ.get('AZURE_ACCOUNT_NAME')
AZURE_CUSTOM_DOMAIN = f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net'
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/media/'
Here is what I tried to implement but with no success:
id_config_file_path = os.path.join(MEDIA_URL, f"{id_config_file}")
id_config_file_path = f"{MEDIA_URL}{id_config_file}"
id_config_file_path = f"{MEDIA_URL}{id_config_file.path}"
id_config_file_path = f"{MEDIA_URL}{id_config_file.url}"
id_config_file_path = f"{MEDIA_URL}{id_config_file.file}"
Question
How to properly set up id_config_file_path, yaml_config_file_path and template_file_path so it will run on Azure when running celery task?