最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - "LookupError: No installed app with label 'admin'." when using muppy in django - Stac

programmeradmin9浏览0评论

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?

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?

Share Improve this question asked Feb 5 at 8:02 Thorben CroiséThorben Croisé 12.9k8 gold badges41 silver badges51 bronze badges 1
  • I added this feature to pympler to solve this for me: github.com/pympler/pympler/pull/168/files With this PR, I could change the code to tr = tracker.SummaryTracker(ignore_types=(LazyObject,)) – Thorben Croisé Commented Feb 5 at 9:04
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论