raise AuditLogRegistrationError on invalid app in settings (#492)

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
This commit is contained in:
Thomas Steen Rasmussen 2023-01-03 16:03:37 +01:00 committed by Ilya
parent 4a56697422
commit fb6c363e2c
2 changed files with 19 additions and 1 deletions

View file

@ -262,7 +262,13 @@ class AuditlogModelRegistry:
self.unregister(model_class)
self.register(model_class)
elif isinstance(model, dict):
model["model"] = self._get_model_classes(model["model"])[0]
appmodel = self._get_model_classes(model["model"])
if not appmodel:
raise AuditLogRegistrationError(
f"An error was encountered while registering model '{model['model']}' - "
"make sure the app is registered correctly."
)
model["model"] = appmodel[0]
self.unregister(model["model"])
self.register(**model)

View file

@ -1158,6 +1158,18 @@ class RegisterModelSettingsTest(TestCase):
):
self.test_auditlog.register_from_settings()
with override_settings(
AUDITLOG_INCLUDE_TRACKING_MODELS=({"model": "notanapp.test"},)
):
with self.assertRaisesMessage(
AuditLogRegistrationError,
(
"An error was encountered while registering model 'notanapp.test'"
" - make sure the app is registered correctly."
),
):
self.test_auditlog.register_from_settings()
with override_settings(AUDITLOG_DISABLE_ON_RAW_SAVE="bad value"):
with self.assertRaisesMessage(
TypeError, "Setting 'AUDITLOG_DISABLE_ON_RAW_SAVE' must be a boolean"