Skip to content

bug: AttributeError: 'dict' object has no attribute 'resolve_closest' #57

@kumaranvpl

Description

@kumaranvpl

Description of the bug

From version 1.2.0, running mkdocs build command results in the error AttributeError: 'dict' object has no attribute 'resolve_closest'. This issue is not happening in version 1.1.0.

I did some digging around, the error obviously happening at https://github.com/mkdocstrings/autorefs/blob/main/src/mkdocs_autorefs/plugin.py#L178 and the self.config returns an empty dictionary. Even at on_config https://github.com/mkdocstrings/autorefs/blob/main/src/mkdocs_autorefs/plugin.py#L211, the self.config value is an empty dictionary. But printing the self.config in mkdocstrings project at https://github.com/mkdocstrings/mkdocstrings/blob/main/src/mkdocstrings/plugin.py#L137 returns some value.

This could be because of incorrect initialization/usage of config variable. Hopefully above info helps with debugging.

Full traceback

Full traceback
File "/home/userdev/project/venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs/commands/build.py", line 337, in build
    _build_page(
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs/commands/build.py", line 226, in _build_page
    output = config.plugins.on_post_page(output, page=page, config=config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs/plugins.py", line 646, in on_post_page
    return self.run_event('post_page', output, page=page, config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs/plugins.py", line 566, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs_autorefs/plugin.py", line 315, in on_post_page
    fixed_output, unmapped = fix_refs(output, url_mapper, _legacy_refs=self.legacy_refs)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs_autorefs/references.py", line 412, in fix_refs
    html = AUTOREF_RE.sub(fix_ref(url_mapper, unmapped), html)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs_autorefs/references.py", line 369, in inner
    url = url_mapper(unescape(identifier))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs_autorefs/plugin.py", line 211, in get_item_url
    url = self._get_item_url(identifier, fallback, from_url)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/userdev/project/venv/lib/python3.12/site-packages/mkdocs_autorefs/plugin.py", line 185, in _get_item_url
    if self.config.resolve_closest and from_url is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'resolve_closest'

Environment information

  • System: Linux-6.9.3-76060903-generic-x86_64-with-glibc2.35
  • Python: cpython 3.12.5
  • Environment variables:
  • Installed packages:
    • mkdocs-autorefs v1.2.0

Metadata

Metadata

Assignees

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