From 2bc132332dba3737048f87876d116be63fa03e3c Mon Sep 17 00:00:00 2001 From: "T. Franzel" Date: Mon, 26 Sep 2022 16:31:02 +0200 Subject: [PATCH] robustify extension class loading #821 --- drf_spectacular/plumbing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drf_spectacular/plumbing.py b/drf_spectacular/plumbing.py index 9ffeecd3..1932a0f9 100644 --- a/drf_spectacular/plumbing.py +++ b/drf_spectacular/plumbing.py @@ -708,6 +708,14 @@ def _load_class(cls): f'has an installed app but target class was not found.' ) cls.target_class = None + except Exception as e: # pragma: no cover + installed_apps = apps.app_configs.keys() + if any(cls.target_class.startswith(app + '.') for app in installed_apps): + warn( + f'Unexpected error {e.__class__.__name__} occurred when attempting ' + f'to import {cls.target_class} for extension {cls.__name__} ({e}).' + ) + cls.target_class = None @classmethod def _matches(cls, target) -> bool: