Django-compressor error with the setup of 2 Cloudflare R2 buckets

I’ve been using two Cloudflare R2 buckets for one Django project. One for static files and another for media files. The goal is to make static files publicly available (via Cloudflare cdn) while keeping media files (they include user uploaded files) private. I’m having some trouble with django-compressor with the current setup.

AWS_ACCESS_KEY_ID = env("CLOUDFLARE_R2_ACCESS_KEY")
AWS_SECRET_ACCESS_KEY = env("CLOUDFLARE_R2_SECRET_ACCESS_KEY")
AWS_QUERYSTRING_AUTH = False
_AWS_EXPIRY = 60 * 60 * 24 * 7
AWS_S3_OBJECT_PARAMETERS = {
    "CacheControl": f"max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate",
}

AWS_S3_MAX_MEMORY_SIZE = env.int(
    "DJANGO_AWS_S3_MAX_MEMORY_SIZE",
    default=100_000_000,  # 100MB
)

AWS_S3_ENDPOINT_URL = env("CLOUDFLARE_R2_ENDPOINT_URL")

AWS_S3_REGION_NAME = env("CLOUDFLARE_R2_REGION_NAME", default=None)

cloudflare_r2_custom_domain = env("CLOUDFLARE_R2_CUSTOM_DOMAIN")
cloudflare_r2_media_domain = env("CLOUDFLARE_R2_MEDIA_DOMAIN")

STORAGES = {
    "default": {
        "BACKEND": "storages.backends.s3.S3Storage",
        "OPTIONS": {
            "bucket_name": env("CLOUDFLARE_R2_MEDIA_STORAGE_BUCKET_NAME"),
            "access_key": env("CLOUDFLARE_R2_MEDIA_ACCESS_KEY"),
            "secret_key": env("CLOUDFLARE_R2_MEDIA_SECRET_ACCESS_KEY"),
            "endpoint_url": env("CLOUDFLARE_R2_ENDPOINT_URL"),
            "region_name": "auto",
            "querystring_auth": True,
            "location": "media",
            "file_overwrite": False,
        },
    },
    "staticfiles": {
        "BACKEND": "storages.backends.s3.S3Storage",
        "OPTIONS": {
            "bucket_name": env("CLOUDFLARE_R2_STORAGE_BUCKET_NAME"),
            "access_key": env("CLOUDFLARE_R2_ACCESS_KEY"),
            "secret_key": env("CLOUDFLARE_R2_SECRET_ACCESS_KEY"),
            "custom_domain": cloudflare_r2_custom_domain,
            "endpoint_url": env("CLOUDFLARE_R2_ENDPOINT_URL"),
            "region_name": "auto",
            "querystring_auth": False,
            "location": "static",
        },
    },
}

MEDIA_URL = f"https://{cloudflare_r2_media_domain}/media/"
COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3Strategy"
STATIC_URL = f"https://{cloudflare_r2_custom_domain}/static/"

# django-compressor
COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True)

COMPRESS_STORAGE = STORAGES["staticfiles"]["BACKEND"]
COMPRESS_URL = STATIC_URL
COMPRESS_FILTERS = {
    "css": [
        "compressor.filters.css_default.CssAbsoluteFilter",
        "compressor.filters.cssmin.rCSSMinFilter",
    ],
    "js": ["compressor.filters.jsmin.JSMinFilter"],
}

When running python3 manage.py compress --force, I got the following:

CommandError: An error occurred during rendering core/detail.html: expected string or bytes-like object, got ‘NoneType’

Unfortunately, the traceback is not giving me useful information. Any idea of what’s going on? Also, how do you usually handle your static files and private files?