diff --git a/CHANGES b/CHANGES index 391a2858a..fcb5bf17c 100644 --- a/CHANGES +++ b/CHANGES @@ -64,6 +64,8 @@ Bugs fixed * #6561: glossary: Wrong hyperlinks are generated for non alphanumeric terms * #6620: i18n: classifiers of definition list are not translated with docutils-0.15 +* #6474: ``DocFieldTransformer`` raises AttributeError when given directive is + not a subclass of ObjectDescription Testing -------- diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 1e8596e5b..dd9854ce6 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -218,7 +218,14 @@ class DocFieldTransformer: def __init__(self, directive: "ObjectDescription") -> None: self.directive = directive - self.typemap = directive.get_field_type_map() + + try: + self.typemap = directive.get_field_type_map() + except Exception: + # for 3rd party extensions directly calls this transformer. + warnings.warn('DocFieldTransformer expects given directive object is a subclass ' + 'of ObjectDescription.', RemovedInSphinx40Warning) + self.typemap = self.preprocess_fieldtypes(directive.__class__.doc_field_types) def preprocess_fieldtypes(self, types: List[Field]) -> Dict[str, Tuple[Field, bool]]: warnings.warn('DocFieldTransformer.preprocess_fieldtypes() is deprecated.',