From 44a501394c7e45e99427e536091744cd3041d0ed Mon Sep 17 00:00:00 2001 From: Charles Oliveira Date: Wed, 24 Apr 2024 16:07:55 -0300 Subject: [PATCH] settings.py: fix 'imp' deprecation warning This was the warning ``` DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses import imp ``` Signed-off-by: Charles Oliveira --- squad/settings.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/squad/settings.py b/squad/settings.py index c34edf0c..0c7a05b4 100644 --- a/squad/settings.py +++ b/squad/settings.py @@ -13,6 +13,7 @@ from celery.schedules import crontab from django.conf import global_settings from email.utils import parseaddr +from importlib.util import find_spec from glob import glob import contextlib import json @@ -55,30 +56,23 @@ # Application definition -try: - import imp - imp.find_module('django_extensions') +django_extensions = None +if find_spec('django_extensions'): django_extensions = 'django_extensions' -except ImportError: - django_extensions = None django_toolbar = None django_toolbar_middleware = None -try: - +django_toolbar_module_spec = find_spec('debug_toolbar') +if django_toolbar_module_spec: DEBUG_TOOLBAR_CONFIG = { 'JQUERY_URL': '', 'SHOW_COLLAPSED': True, 'SHOW_TOOLBAR_CALLBACK': 'squad.frontend.utils.show_debug_toolbar', } - import imp - imp.find_module('debug_toolbar') django_toolbar = 'debug_toolbar' django_toolbar_middleware = 'debug_toolbar.middleware.DebugToolbarMiddleware' INTERNAL_IPS = ['127.0.0.1'] -except ImportError: - pass django_allauth_middleware = None @@ -445,6 +439,9 @@ # Django's default is 2.5MB, which is a bit low DATA_UPLOAD_MAX_MEMORY_SIZE = 10485760 # 10MB +# Django requires that this specification is present in settings.py +DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' + try: from squad.local_settings import * # noqa: F401,F403 except ImportError: