Opened 7 years ago

Last modified 7 years ago

#28703 closed Cleanup/optimization

URL regex for admin's app_index view isn't constructed deterministically — at Version 1

Reported by: Erik Bryant Owned by: nobody
Component: contrib.admin Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

https://github.com/django/django/blob/master/django/contrib/admin/sites.py#L277

The regex pattern that is constructed for an endpoint is not stable. For instance, in my project I have seen it construct each of the following:

^admin/^(?P<app_label>social_django|authtoken|queues|jobs|files|users|clusters|appps|auth|vdcs)/$
^admin/^(?P<app_label>social_django|auth|users|vdcs|appps|jobs|queues|authtoken|clusters|files)/$
^admin/^(?P<app_label>authtoken|appps|social_django|clusters|users|queues|jobs|vdcs|auth|files)/$
^admin/^(?P<app_label>authtoken|appps|social_django|clusters|users|queues|vdcs|jobs|auth|files)/$

This precludes the use of patterns in unit tests.

https://github.com/django/django/pull/9230

Change History (1)

comment:1 by Tim Graham, 7 years ago

Description: modified (diff)
Summary: Endpoint regex pattern construction is not stableURL regex for admin's app_index view isn't constructed deterministically
Type: UncategorizedCleanup/optimization

It seems to me that such a URL introspection test in your project is testing an internal implementation in Django that could be subject to change in the future. Can you give an idea of what regressions you're looking to test for? I wonder if a test that inspects _registry (or perhaps better yet, uses the site.is_registered() method) would be more appropriate.

Note: See TracTickets for help on using tickets.
Back to Top