My pytest suite is currently not working, as the reverse lookup is failing
for admin views; for example, trying to access
`reverse('admin:myapp_mymodel_changelist')` or
`reverse_lazy('admin:myapp_mymodel_changelist')`.

I have narrowed down the cause to the trigger being *any* kind of import
being made from the `admin.py` code for that app; the available URLs are
still there for all the other apps but *not* for the one being imported.

In `django/urls/resolvers.py` package, the available possible matches are
determined here:

    possibilities = self.reverse_dict.getlist(lookup_view)

And one can add a debug statement which shows all the keys:

    keys = [key for key in [*self.reverse_dict] if isinstance(key, str)]
    print(keys)

Some basic test code, which I run in the Django shell, demonstrates how the
failure is triggered, and shows that this is not an artefact related to the
tests themselves:

    from django.core.urlresolvers import reverse_lazy
    from myapp.admin import MyModelAdmin
    print(reverse_lazy('admin:myapp_mymodel_changelist'))

But this passes:

    from django.core.urlresolvers import reverse_lazy
    print(reverse_lazy('admin:myapp_mymodel_changelist'))

i.e. if I comment out the import line the code works, otherwise it fails.

Any ideas on why Django is failing when importing from the app's admin?

Thanks
Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF1Wu3Mdz08vD74vsBWQOT1UNDTqRXOV0C57rz%3DiXXH-TPiFCA%40mail.gmail.com.

Reply via email to