Remove use of storage wrappers
Use a dynamic subclass instead that always deconstructs to a fake subclass with a __eq__ method that always returns True. This should trick makemigrations into never creating a new migrations for changes to the storage class or the arguments. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -12,6 +12,7 @@ from django.urls.base import get_script_prefix
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.http import urlencode as django_urlencode
|
||||
from django.utils.http import urlquote as django_urlquote
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.six.moves import reduce as reduce_function
|
||||
from django.utils.six.moves import xmlrpc_client
|
||||
|
||||
@@ -100,6 +101,28 @@ def get_descriptor(file_input, read=True):
|
||||
return file_input
|
||||
|
||||
|
||||
def get_storage_subclass(dotted_path):
|
||||
"""
|
||||
Import a storage class and return a subclass that will always return eq
|
||||
True to avoid creating a new migration when for runtime storage class
|
||||
changes.
|
||||
"""
|
||||
imported_storage_class = import_string(dotted_path=dotted_path)
|
||||
|
||||
class StorageSubclass(imported_storage_class):
|
||||
def __init__(self, *args, **kwargs):
|
||||
return super(StorageSubclass, self).__init__(*args, **kwargs)
|
||||
|
||||
def __eq__(self, other):
|
||||
return True
|
||||
|
||||
def deconstruct(self):
|
||||
return ('mayan.apps.common.classes.FakeStorageSubclass', (), {})
|
||||
|
||||
|
||||
return StorageSubclass
|
||||
|
||||
|
||||
def TemporaryFile(*args, **kwargs):
|
||||
kwargs.update({'dir': setting_temporary_directory.value})
|
||||
return tempfile.TemporaryFile(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user