DiamondLightSource / DiamondLightSource/mkdocs-topic-nav

deepcopy(nav) causes RecursionError as navigation grows

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Both _filter_topic_nav and _filter_section_nav use deepcopy(nav) to create a mutable copy of the navigation before filtering it. The MkDocs Navigation object has circular references (Page.ancestors → Section → Section.children → Page → ...), so deepcopy recursively traverses these until it hits Python's recursion limit. The issue doesn't surface on small sites but triggers once the nav is big enough

How to reproduce - Any mkdocs project using topic-nav with enough pages in the navigation. Adding pages to an existing site that was previously just under the limit will suddenly break the build.

I came across this when adding a page to diamond's dev-guide:

```
...
File "/usr/local/lib/python3.9/dist-packages/mkdocs/plugins.py", line 507, in run_event
result = method(item, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/mkdocs_topic_nav/plugin.py", line 33, in on_page_context
context["nav"] = self._filter_topic_nav(nav, page)
File "/usr/local/lib/python3.9/dist-packages/mkdocs_topic_nav/plugin.py", line 63, in _filter_topic_nav
new_nav = deepcopy(nav)
File "/usr/lib/python3.9/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib/python3.9/copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.9/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.9/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.9/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.9/copy.py", line 205, in _deepcopy_list
append(deepcopy(a, memo))
File "/usr/lib/python3.9/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
...
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in mkdocs_topic_nav/plugin.py at _filter_topic_nav and _filter_section_nav, where the issue identifies deepcopy(nav) as the failing operation. Reproduce the build with a sufficiently large navigation, then verify that topic and section filtering complete without RecursionError while preserving the filtered navigation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.