# Buggy code
def _walk(self, tree, topdown=True):
    dirs, nondirs = [], []
    for i in _iter_tree(tree):
        if i.mode == GIT_MODE_DIR:
            dirs.append(i.name)
        else:
            nondirs.append(i.name)

    if topdown:
        yield os.path.normpath(tree.abspath), dirs, nondirs

    for i in dirs:
        yield from self._walk(tree[i], topdown=topdown)

    if not topdown:
        yield os.path.normpath(tree.abspath), dirs, nondirs


# Traceback (KeyError)
2020-03-16 09:53:37,900 ERROR: unexpected error - 'be23d78966ad0171e87879e051edf6eb3f446e12'
------------------------------------------------------------
Traceback (most recent call last):
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/main.py", line 50, in main
ret = cmd.run()
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/command/gc.py", line 60, in run
workspace=self.args.workspace,
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/repo/__init__.py", line 27, in wrapper
ret = f(repo, *args, **kwargs)
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/repo/gc.py", line 75, in gc
jobs=jobs,
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/repo/__init__.py", line 256, in used_cache
for stage, filter_info in pairs:
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/repo/__init__.py", line 252, in <genexpr>
for target in targets
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/repo/__init__.py", line 202, in collect_granular
return [(stage, None) for stage in self.stages]
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/funcy/objects.py", line 28, in __get__
res = instance.__dict__[self.fget.__name__] = self.fget(instance)
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/repo/__init__.py", line 397, in stages
for root, dirs, files in self.tree.walk(self.root_dir):
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/ignore.py", line 135, in walk
dirs[:], files[:] = self.dvcignore(root, dirs, files)
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/funcy/objects.py", line 28, in __get__
res = instance.__dict__[self.fget.__name__] = self.fget(instance)
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/ignore.py", line 115, in dvcignore
return DvcIgnoreFilter(self.tree)
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/ignore.py", line 93, in __init__
for root, dirs, files in self.tree.walk(self.tree.tree_root):
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/scm/git/tree.py", line 148, in walk
yield from self._walk(tree, topdown=topdown)
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/scm/git/tree.py", line 131, in _walk
yield from self._walk(tree[i], topdown=topdown)
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/scm/git/tree.py", line 121, in _walk
for i in _iter_tree(tree):
File "/home/my_user/data/env/my_project/lib/python3.6/site-packages/dvc/scm/git/tree.py", line 26, in _iter_tree
node = submodules[node.hexsha]
KeyError: 'be23d78966ad0171e87879e051edf6eb3f446e12'

# Fixed code
def _walk(self, tree, topdown=True):
    dirs, nondirs = [], []
    for item in tree:
        name = _item_basename(item)
        if item.mode == GIT_MODE_DIR:
            dirs.append(name)
        else:
            nondirs.append(name)

    if topdown:
        yield os.path.normpath(tree.abspath), dirs, nondirs

    for i in dirs:
        yield from self._walk(tree[i], topdown=topdown)

    if not topdown:
        yield os.path.normpath(tree.abspath), dirs, nondirs