diff --git a/django/contrib/contenttypes/tests.py b/django/contrib/contenttypes/tests.py
index 1854664..36179c0 100644
a
|
b
|
class FooWithUrl(FooWithoutUrl):
|
30 | 30 | def get_absolute_url(self): |
31 | 31 | return "/users/%s/" % urllib.quote(smart_str(self.name)) |
32 | 32 | |
| 33 | class FooWithBrokenAbsoluteUrl(FooWithoutUrl): |
| 34 | """ |
| 35 | Fake model defining a ``get_absolute_url`` method containing an error |
| 36 | """ |
| 37 | |
| 38 | def get_absolute_url(self): |
| 39 | return "/users/%s/" % self.unknown_field |
33 | 40 | |
34 | 41 | class ContentTypesTests(TestCase): |
35 | 42 | |
… |
… |
class ContentTypesTests(TestCase):
|
135 | 142 | |
136 | 143 | self.assertRaises(Http404, shortcut, request, user_ct.id, obj.id) |
137 | 144 | |
| 145 | def test_shortcut_view_with_broken_get_absolute_url(self): |
| 146 | """ |
| 147 | Check that the shortcut view does not catch an AttributeError raised |
| 148 | by the model's get_absolute_url method. |
| 149 | """ |
| 150 | |
| 151 | request = HttpRequest() |
| 152 | request.META = { |
| 153 | "SERVER_NAME": "Example.com", |
| 154 | "SERVER_PORT": "80", |
| 155 | } |
| 156 | user_ct = ContentType.objects.get_for_model(FooWithBrokenAbsoluteUrl) |
| 157 | obj = FooWithBrokenAbsoluteUrl.objects.create(name="john") |
| 158 | |
| 159 | self.assertRaises(AttributeError, shortcut, request, user_ct.id, obj.id) |
| 160 | |
138 | 161 | def test_missing_model(self): |
139 | 162 | """ |
140 | 163 | Ensures that displaying content types in admin (or anywhere) doesn't |
diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py
index ac0feff..e9802b0 100644
a
|
b
|
def shortcut(request, content_type_id, object_id):
|
14 | 14 | except (ObjectDoesNotExist, ValueError): |
15 | 15 | raise http.Http404("Content type %s object %s doesn't exist" % (content_type_id, object_id)) |
16 | 16 | try: |
17 | | absurl = obj.get_absolute_url() |
| 17 | get_absolute_url = obj.get_absolute_url |
18 | 18 | except AttributeError: |
19 | | raise http.Http404("%s objects don't have get_absolute_url() methods" % content_type.name) |
| 19 | raise http.Http404("%s objects don't have a get_absolute_url() method" % content_type.name) |
| 20 | absurl = get_absolute_url() |
20 | 21 | |
21 | 22 | # Try to figure out the object's domain, so we can do a cross-site redirect |
22 | 23 | # if necessary. |