# Buggy code
def process(self, doctree: nodes.document, docname: str) -> None:
    todos = sum(self.domain.todos.values(), [])  # type: List[todo_node]
    for node in doctree.traverse(todolist):
        if not self.config.todo_include_todos:
            node.parent.remove(node)
            continue

        if node.get("ids"):
            content = [nodes.target()]  # type: List[Element]
        else:
            content = []

        for todo in todos:
            # Create a copy of the todo node
            new_todo = todo.deepcopy()
            new_todo["ids"].clear()

            # (Recursively) resolve references in the todo content
            self.env.resolve_references(new_todo, todo["docname"], self.builder)  # type: ignore  # NOQA
            content.append(new_todo)

            todo_ref = self.create_todo_reference(todo, docname)
            content.append(todo_ref)

        node.replace_self(content)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/cmd/build.py", line 276, in build_main
app.build(args.force_all, filenames)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/application.py", line 349, in build
self.builder.build_update()
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 299, in build_update
len(to_build))
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 361, in build
self.write(docnames, list(updated_docnames), method)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 535, in write
self._write_serial(sorted(docnames))
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 542, in _write_serial
doctree = self.env.get_and_resolve_doctree(docname, self)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/environment/__init__.py", line 537, in get_and_resolve_doctree
self.apply_post_transforms(doctree, docname)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/environment/__init__.py", line 588, in apply_post_transforms
self.events.emit('doctree-resolved', doctree, docname)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/events.py", line 99, in emit
results.append(callback(self.app, *args))
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/ext/todo.py", line 158, in __init__
self.process(doctree, docname)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/ext/todo.py", line 178, in process
self.env.resolve_references(new_todo, todo['docname'], self.builder)  # type: ignore  # NOQA
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/environment/__init__.py", line 571, in resolve_references
self.apply_post_transforms(doctree, fromdocname)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/environment/__init__.py", line 588, in apply_post_transforms
self.events.emit('doctree-resolved', doctree, docname)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinx/events.py", line 99, in emit
results.append(callback(self.app, *args))
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/sphinxcontrib/trimblank.py", line 122, in trimblank
doctree.walk(visitor)
File "/home/gohki/.venv/sphinx/lib/python3.7/site-packages/docutils/nodes.py", line 129, in walk
visitor.document.reporter.debug(
AttributeError: 'todo_node' object has no attribute 'reporter'

# Fixed code
def process(self, doctree: nodes.document, docname: str) -> None:
    todos = sum(self.domain.todos.values(), [])  # type: List[todo_node]
    document = new_document("")
    for node in doctree.traverse(todolist):
        if not self.config.todo_include_todos:
            node.parent.remove(node)
            continue

        if node.get("ids"):
            content = [nodes.target()]  # type: List[Element]
        else:
            content = []

        for todo in todos:
            # Create a copy of the todo node
            new_todo = todo.deepcopy()
            new_todo["ids"].clear()

            # (Recursively) resolve references in the todo content
            #
            # Note: To resolve references, it is needed to wrap it with document node
            document += new_todo
            self.env.resolve_references(document, todo["docname"], self.builder)
            document.remove(new_todo)
            content.append(new_todo)

            todo_ref = self.create_todo_reference(todo, docname)
            content.append(todo_ref)

        node.replace_self(content)