You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: I'm only running into this issue in my CI/CD pipeline, because I am using tox to create an isolated python 3.8 environment to run all my django/python unit tests.
In my settings.py I set STATIC_FILES_STORAGE to use MinioBackendStatic to serve all my static files from my minio server, because of this I get a ConnectionError when the tox environment starts up, this library makes a call to check the buckets exist at django_minio_backend/apps.py#L32.
Because this is an isolated python environment specifically used for testing, it can't really reach out to ensure any buckets exist. By looking at the source code, it doesn't seem like there's a way to prevent the call to mbs.check_bucket_existence() unless I don't set STATICFILES_STORAGE = "django_minio_backend.models.MinioBackendStatic" in my settings.py file whenever I'm running this tox environment, which is not an elegant solution IMO.
I'm basically looking for any guidance on how to get around this a bit more elegantly. I'm also open to opening up a pull request to introduce an additional (or reuse MINIO_CONSISTENCY_CHECK_ON_START) configuration setting in that line of code to not check for bucket existence e.g.
There are 2 places where this needs to be done, in apps.py:
consistency_check_on_start=get_setting('MINIO_CONSISTENCY_CHECK_ON_START', False)
# other code goes here...# Validate static storage and default storage configurationsstaticfiles_storage: str=get_setting('STATICFILES_STORAGE')
ifstaticfiles_storage.endswith(MinioBackendStatic.__name__):
mbs=MinioBackendStatic()
# This is my proposed change - this entire line could also be removed entirely# since the init method of MinioBackendStatic already checks for bucket existenceifconsistency_check_on_start:
mbs.check_bucket_existence()
and in models.py
@deconstructibleclassMinioBackendStatic(MinioBackend):
""" MinIO-compatible Django custom storage system for Django static files. The used bucket can be configured in settings.py through `MINIO_STATIC_FILES_BUCKET` :arg *args: Should not be used for static files. It's here for compatibility only :arg **kwargs: Should not be used for static files. It's here for compatibility only """def__init__(self, *args, **kwargs):
super().__init__(self.MINIO_STATIC_FILES_BUCKET, *args, **kwargs)
consistency_check_on_start=get_setting('MINIO_CONSISTENCY_CHECK_ON_START', False)
ifconsistency_check_on_start: # This is my proposed changeself.check_bucket_existence() # make sure the `MINIO_STATIC_FILES_BUCKET` existsself.set_bucket_to_public() # the static files bucket must be publicly available
The text was updated successfully, but these errors were encountered:
I see your problem and I think your proposal to reuse MINIO_CONSISTENCY_CHECK_ON_START is a good call. I would like to avoid introducing yet another configuration parameter.
You're right about the proposed changes in those two places, but in the case of MinioBackendStatic, the last line calling self.set_bucket_to_public() should be indented into the if branch as well. Otherwise it may raise an Exception while trying to manipulate a non-existing bucket. At least that's what I suspect to happen.
Please feel free to open a PR, and I'll check it out ASAP.
Note: I'm only running into this issue in my CI/CD pipeline, because I am using tox to create an isolated python 3.8 environment to run all my django/python unit tests.
In my
settings.py
I setSTATIC_FILES_STORAGE
to useMinioBackendStatic
to serve all my static files from my minio server, because of this I get a ConnectionError when the tox environment starts up, this library makes a call to check the buckets exist at django_minio_backend/apps.py#L32.Screenshot of stacktrace on startup
Because this is an isolated python environment specifically used for testing, it can't really reach out to ensure any buckets exist. By looking at the source code, it doesn't seem like there's a way to prevent the call to
mbs.check_bucket_existence()
unless I don't setSTATICFILES_STORAGE = "django_minio_backend.models.MinioBackendStatic"
in mysettings.py
file whenever I'm running this tox environment, which is not an elegant solution IMO.I'm basically looking for any guidance on how to get around this a bit more elegantly. I'm also open to opening up a pull request to introduce an additional (or reuse
MINIO_CONSISTENCY_CHECK_ON_START
) configuration setting in that line of code to not check for bucket existence e.g.There are 2 places where this needs to be done, in apps.py:
and in models.py
The text was updated successfully, but these errors were encountered: