Search code examples
djangodjango-import-exportdjango-storage

django-import-export: Customizable storage not working with minio


Following the documentation, I'm trying to configure the library to store temporary import files from the admin page into a MinIO bucket.

This is my STORAGES configuration:


IMPORT_EXPORT_TMP_STORAGE_CLASS = "import_export.tmp_storages.MediaStorage"

STORAGES = {
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
    },
    "import_export": {
        "BACKEND": "storages.backends.s3.S3Storage",
        "OPTIONS": {
            "bucket_name": os.getenv("PORTAL_S3_BUCKET_NAME"),
            "region_name": os.getenv("PORTAL_S3_REGION_NAME"),
            "access_key": os.getenv("PORTAL_S3_ACCESS_KEY"),
            "secret_key": os.getenv("PORTAL_S3_SECRET_KEY"),
            "endpoint_url": os.getenv("PORTAL_S3_ENDPOINT_URL"),
        },
    },
}

I suppose that when I import a file from the admin page and reach the confirmation step, I should be able to see the file I'm trying to upload in the bucket, but that's not happening. Nothing is being uploaded.

When not setting anything relative to storage and using the default host server storage, I can see the files in the host machine once I'm in the confirmation step, so I assume I should be able to see the file in the bucket as well once it's configured.

I've also tried to debug the library, but I am not able to see any information regarding the connection to the bucket.

The problem has nothing to do with the MinIO configuration. I've tried retrieving and uploading files to the bucket using Postman with the keys I use in the STORAGES dict and works like a charm.

I don't know what else to do because the configuration is not complex or flexible, so I don't really have more options to try.

The versions of the libraries I'm using are:

boto3==1.34.131
Django==4.2.11
django-storages==1.14.3
django-import-export==4.0.8

Solution

  • I think this is a bug in django-import-export. The Django docs state that STORAGES should be used for Django v4.2 and greater, however django-import-export doesn't check for this correctly. I'll raise it as a bug.

    If you can't wait for a fix, could you upgrade to Django 5.0?

    UPDATE

    This is fixed in v4.0.10