# Buggy code
def show_project(request, project):
    obj = get_project(request, project)
    user = request.user

    dict_langs = (
        Language.objects.filter(dictionary__project=obj)
        .annotate(Count("dictionary"))
        .order()
    )

    last_changes = Change.objects.prefetch().order().filter(project=obj)[:10]

    language_stats = sort_unicode(
        obj.stats.get_language_stats(), lambda x: force_text(x.language.name)
    )

    # Paginate components of project.
    all_components = obj.component_set.select_related().order()
    components = prefetch_stats(get_paginator(request, all_components))

    return render(
        request,
        "project.html",
        {
            "allow_index": True,
            "object": obj,
            "project": obj,
            "dicts": dict_langs,
            "last_changes": last_changes,
            "last_changes_url": urlencode({"project": obj.slug}),
            "language_stats": language_stats,
            "search_form": SearchForm(),
            "whiteboard_form": optional_form(WhiteboardForm, user, "project.edit", obj),
            "delete_form": optional_form(
                DeleteForm, user, "project.edit", obj, obj=obj
            ),
            "rename_form": optional_form(
                ProjectRenameForm,
                user,
                "project.edit",
                obj,
                request=request,
                instance=obj,
            ),
            "replace_form": optional_form(ReplaceForm, user, "unit.edit", obj),
            "bulk_state_form": optional_form(
                BulkStateForm, user, "translation.auto", obj, user=user, obj=obj
            ),
            "components": components,
            "licenses": ", ".join(
                sorted(
                    all_components.exclude(license="").values_list("license", flat=True)
                )
            ),
        },
    )


# Traceback (TypeError)
weblate@jb9:~$ ./venv/bin/weblate list_versions
* Weblate 3.6.1
* Python 3.5.3
* Django 2.2.1
* Celery 4.3.0
* celery-batches 0.2
* six 1.12.0
* social-auth-core 3.2.0
* social-auth-app-django 3.1.0
* django-appconf 1.0.3
* translate-toolkit 2.3.1
* translation-finder 1.5
* Whoosh 2.7.4
* defusedxml 0.6.0
* Git 2.11.0
* Pillow 6.0.0
* python-dateutil 2.8.0
* lxml 4.3.3
* django-crispy-forms 1.7.2
* django_compressor 2.2
* djangorestframework 3.9.4
* user-agents 2.0
* jellyfish 0.7.1
* diff-match-patch 20121119
* pytz 2019.1
* pyuca 1.2
* python-bidi 0.4.0
* PyYAML 5.1
* hub 2.3.0-pre10
* Database backends: django.db.backends.postgresql_psycopg2
* Cache backends: avatar:FileBasedCache, default:RedisCache
* Celery: redis://127.0.0.1:6379/3, redis://127.0.0.1:6379/3, regular
* Platform: Linux 4.9.0-9-amd64 (x86_64)
Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x7f0db6159950>
Traceback (most recent call last):
File "/var/www/weblate/venv/lib/python3.5/weakref.py", line 117, in remove
TypeError: 'NoneType' object is not callable
Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x7f0db6159950>
Traceback (most recent call last):
File "/var/www/weblate/venv/lib/python3.5/weakref.py", line 117, in remove
TypeError: 'NoneType' object is not callable

# Fixed code
def show_project(request, project):
    obj = get_project(request, project)
    user = request.user

    dict_langs = (
        Language.objects.filter(dictionary__project=obj)
        .annotate(Count("dictionary"))
        .order()
    )

    last_changes = Change.objects.prefetch().order().filter(project=obj)[:10]

    language_stats = sort_unicode(
        obj.stats.get_language_stats(), lambda x: force_text(x.language.name)
    )

    # Paginate components of project.
    all_components = obj.component_set.prefetch().order()
    components = prefetch_stats(get_paginator(request, all_components))

    return render(
        request,
        "project.html",
        {
            "allow_index": True,
            "object": obj,
            "project": obj,
            "dicts": dict_langs,
            "last_changes": last_changes,
            "last_changes_url": urlencode({"project": obj.slug}),
            "language_stats": language_stats,
            "search_form": SearchForm(),
            "whiteboard_form": optional_form(WhiteboardForm, user, "project.edit", obj),
            "delete_form": optional_form(
                DeleteForm, user, "project.edit", obj, obj=obj
            ),
            "rename_form": optional_form(
                ProjectRenameForm,
                user,
                "project.edit",
                obj,
                request=request,
                instance=obj,
            ),
            "replace_form": optional_form(ReplaceForm, user, "unit.edit", obj),
            "bulk_state_form": optional_form(
                BulkStateForm, user, "translation.auto", obj, user=user, obj=obj
            ),
            "components": components,
            "licenses": ", ".join(
                sorted(
                    all_components.exclude(license="").values_list("license", flat=True)
                )
            ),
        },
    )