# Buggy code
def load_pymathics_doc(self):
    if self.pymathics_doc_loaded:
        return
    from mathics.settings import default_pymathics_modules

    pymathicspart = None
    # Look the "Pymathics Modules" part, and if it does not exist, create it.
    for part in self.parts:
        if part.title == "Pymathics Modules":
            pymathicspart = part
    if pymathicspart is None:
        pymathicspart = DocPart(self, "Pymathics Modules", is_reference=True)
        self.parts.append(pymathicspart)

    # For each module, create the documentation object and load the chapters in the pymathics part.
    for pymmodule in default_pymathics_modules:
        pymathicsdoc = PyMathicsDocumentation(pymmodule)
        for part in pymathicsdoc.parts:
            for ch in part.chapters:
                ch.title = f"{pymmodule.name} {part.title} {ch.title}"
                ch.part = pymathicspart
                pymathicspart.chapters_by_slug[ch.slug] = ch
                pymathicspart.chapters.append(ch)

    self.pymathics_doc_loaded = True


# Traceback (KeyError)
$ mathicsserver
warning: database file /home/pablo/.local/var/mathics/mathics.sqlite not found

Migrating database /home/pablo/.local/var/mathics/mathics.sqlite
Traceback (most recent call last):
File "/home/pablo/Documents/Mathics/mathics/manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
self.check()
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 65, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/home/pablo/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/home/pablo/.local/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/pablo/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 571, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/pablo/.local/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/pablo/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/pablo/Documents/Mathics/mathics/urls.py", line 14, in <module>
url(r'^', include('mathics.web.urls')),
File "/home/pablo/.local/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/pablo/Documents/Mathics/mathics/web/urls.py", line 6, in <module>
from mathics.web.views import query, main_view, login, logout, save, open, get_worksheets, doc_search, doc_part, doc_chapter, doc_section, doc
File "/home/pablo/Documents/Mathics/mathics/web/views.py", line 28, in <module>
documentation.load_pymathics_doc()
File "/home/pablo/Documents/Mathics/mathics/doc/doc.py", line 727, in load_pymathics_doc
pymathicsdoc = PyMathicsDocumentation(pymmodule)
File "/home/pablo/Documents/Mathics/mathics/doc/doc.py", line 765, in __init__
self.name = self.pymathicsmodule.pymathics_version_data['name']
KeyError: 'name'
error: failed to create database

# Fixed code
def load_pymathics_doc(self):
    if self.pymathics_doc_loaded:
        return
    from mathics.settings import default_pymathics_modules

    pymathicspart = None
    # Look the "Pymathics Modules" part, and if it does not exist, create it.
    for part in self.parts:
        if part.title == "Pymathics Modules":
            pymathicspart = part
    if pymathicspart is None:
        pymathicspart = DocPart(self, "Pymathics Modules", is_reference=True)
        self.parts.append(pymathicspart)

    # For each module, create the documentation object and load the chapters in the pymathics part.
    for pymmodule in default_pymathics_modules:
        pymathicsdoc = PyMathicsDocumentation(pymmodule)
        for part in pymathicsdoc.parts:
            for ch in part.chapters:
                ch.title = f"{pymmodule} {part.title} {ch.title}"
                ch.part = pymathicspart
                pymathicspart.chapters_by_slug[ch.slug] = ch
                pymathicspart.chapters.append(ch)

    self.pymathics_doc_loaded = True