Skip to content

If two different handlers are used in one document, the jinja env is not updated #502

@jdpatt

Description

@jdpatt

Found another issue/question with what I was trying to do with a custom handler.

If one document has two identifiers that use different handlers; only the first one's env is updated. My templates error out because the default mkdocstring filters are missing (highlight, heading or convert_markdown) don't exist in the second handler yet and instead I only have the built-in jinja filters and the any filter that is added when the env is initialized.

::: mkdocstrings_handlers.custom_handler.other_module.AccessTypes
    handler: python

::: demo.custom_identifier.stuff
    handler: custom_handler

It looks like these few lines are the offenders and I'm curious if there is a drawback to updating it every time, updating the env on init or make the _updated_env a part of the handler and not the extension? Commenting out self._updated_env = True is enough to resolve this issue.

        if not self._updated_env:
            log.debug("Updating renderer's env")
            handler._update_env(self.md, self._config)  # noqa: WPS437 (protected member OK)
            self._updated_env = True

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions