Opened 2 years ago

Last modified 11 months ago

#35418 assigned Cleanup/optimization

ValueError: site must subclass AdminSite

Reported by: Lily Foote Owned by: Ahmed Nassar
Component: Utilities Version: 5.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In https://code.djangoproject.com/ticket/28358#comment:13 it was reported that running tests with Django, PyPy and Coverage would fail with a ValueError: site must subclass AdminSite exception. This can also be triggered on CPython when running Coverage in pure python mode. There are upstream tickets for ​Coverage, ​PyPy and ​CPython, but these are not seeing much progress. A small change to Django to workaround this was proposed in https://code.djangoproject.com/ticket/28358#comment:21, but this never landed: ​https://github.com/django/django/pull/16541

I think we should land the workaround in Django so this isn't an issue even if upstream never finds a fix.

Change History (6)

comment:1 by Sarah Boyce, 2 years ago

Component: Uncategorized → Utilities
Triage Stage: Unreviewed → Accepted
Type: Uncategorized → Cleanup/optimization

Hey Lily, thank you for creating this ticket and summarizing the current situation, including the update of the PyPy bug link.
This is a tricky one - tentatively accepting to track further investigation of a workaround. A fix in CPython or PyPy sounds preferable and if these start progressing, this will likely be closed as a wontfix.
But discussed with Natalia, and we're happy to look at a PR proposing the mentioned workaround (a test would also be needed, which from comments in #28358 that may be challenging).

comment:2 by Mohammad Salehi, 2 years ago

Hello, if you're okay with it, I would like to start working on this ticket and submit a PR to address the issue.

comment:3 by Ahmed Nassar, 18 months ago

Owner: changed from nobody to Ahmed Nassar
Status: new → assigned

comment:4 by Carsten Agger, 11 months ago

Is there any progress on this?

I still have this problem on Django 5.2.8 with Pypy 3.10.16 / 7.3.19. The workaround referenced above doesn't work with these versions, so right now I'm at a loss regarding how to get Django to run with Pypy.

comment:5 by Carsten Agger, 11 months ago

OK, I found a workaround which could hold during development:

--- a/django/contrib/admin/decorators.py
+++ b/django/contrib/admin/decorators.py
@@ -98,8 +98,8 @@ def register(*models, site=None):
 
         admin_site = site or default_site
 
-        if not isinstance(admin_site, AdminSite):
-            raise ValueError("site must subclass AdminSite")
+        # if not isinstance(admin_site, AdminSite):
+        #    raise ValueError("site must subclass AdminSite")
 
         if not issubclass(admin_class, ModelAdmin):
             raise ValueError("Wrapped class must subclass ModelAdmin.")

This at least makes tests pass. It remains to be seen if it actually works in practice.

comment:6 by Carsten Agger, 11 months ago

If somebody reads this and knows a genuinely good workaround (that doesn't involve commenting out a check that probably should be there) I'd like to hear about it.

Last edited 11 months ago by Carsten Agger (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top