"LookupError: No installed app with label 'admin'." when using muppy in django
I have a django + drf application that has no admin site, which works very well for us. However, when using pympler and muppy like this:
class DashboardViewSet(
SpecialEndpoint,
):
def list(self, request, *args, **kwargs):
from pympler import tracker
tr = tracker.SummaryTracker()
[...]
tr.print_diff()
return Response(...)
I get this error:
File "src/api/views/case_manager/dashboard/dashboard_viewset.py", line 33, in list
tr = tracker.SummaryTracker()
File "lib/python3.13/site-packages/pympler/tracker.py", line 45, in __init__
self.s0 = summary.summarize(muppy.get_objects())
~~~~~~~~~~~~~~~~~^^
File "lib/python3.13/site-packages/pympler/muppy.py", line 42, in get_objects
tmp = [o for o in tmp if not ignore_object(o)]
~~~~~~~~~~~~~^^^
File "lib/python3.13/site-packages/pympler/muppy.py", line 17, in ignore_object
return isframe(obj)
File "lib/python3.13/inspect.py", line 507, in isframe
return isinstance(object, types.FrameType)
File "lib/python3.13/site-packages/django/utils/functional.py", line 280, in __getattribute__
value = super().__getattribute__(name)
File "lib/python3.13/site-packages/django/utils/functional.py", line 251, in inner
self._setup()
~~~~~~~~~~~^^
File "lib/python3.13/site-packages/django/contrib/admin/sites.py", line 605, in _setup
AdminSiteClass = import_string(apps.get_app_config("admin").default_site)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "lib/python3.13/site-packages/django/apps/registry.py", line 165, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'admin'.
This seems to happen as a DefaultAdminSite is always created, lazily, in a global variable, which muppy accesses to get the size.
Any idea how to work around this?
Ensure that the admin
app is present in the INSTALLED_APPS
list in your settings.py
file:
INSTALLED_APPS = [
'django.contrib.admin', # Ensure this line is present
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# other apps...
]
If the issue persists, please provide more details about the error or your project structure.