Code

Ticket #13051: ns.diff

File ns.diff, 2.5 KB (added by apollo13, 4 years ago)
Line 
1diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
2index 3bb2c1c..fb21808 100644
3--- a/django/core/urlresolvers.py
4+++ b/django/core/urlresolvers.py
5@@ -338,7 +338,8 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current
6                 elif ns not in app_list:
7                     # The name isn't shared by one of the instances (i.e., the default)
8                     # so just pick the first instance as the default.
9-                    ns = app_list[0]
10+                    # We actually use the last as the list is reversed!
11+                    ns = app_list[-1]
12             except KeyError:
13                 pass
14 
15diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
16index d5f3ec9..e6dc262 100644
17--- a/tests/regressiontests/urlpatterns_reverse/tests.py
18+++ b/tests/regressiontests/urlpatterns_reverse/tests.py
19@@ -242,13 +242,13 @@ class NamespaceTests(TestCase):
20 
21     def test_app_lookup_object_without_default(self):
22         "An application namespace without a default is sensitive to the 'current' app can be used for lookup"
23-        self.assertEquals('/other2/inner/', reverse('nodefault:urlobject-view'))
24-        self.assertEquals('/other2/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42]))
25-        self.assertEquals('/other2/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
26+        self.assertEquals('/other1/inner/', reverse('nodefault:urlobject-view'))
27+        self.assertEquals('/other1/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42]))
28+        self.assertEquals('/other1/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
29 
30-        self.assertEquals('/other1/inner/', reverse('nodefault:urlobject-view', current_app='other-ns1'))
31-        self.assertEquals('/other1/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42], current_app='other-ns1'))
32-        self.assertEquals('/other1/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}, current_app='other-ns1'))
33+        self.assertEquals('/other2/inner/', reverse('nodefault:urlobject-view', current_app='other-ns2'))
34+        self.assertEquals('/other2/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42], current_app='other-ns2'))
35+        self.assertEquals('/other2/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}, current_app='other-ns2'))
36 
37 class RequestURLconfTests(TestCase):
38     def setUp(self):