summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorAhmed Nassar <a.moh.nassar00@gmail.com>2025-03-21 17:13:36 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-04-02 09:33:13 +0200
commit00c68f03b5dc6c14618026347ee0da4d466c88e3 (patch)
tree4e02e8a71f5de819ace5887cb54ea11ed8467783 /tests/contenttypes_tests
parentbe1b776ad8d6f9bccfbdf63f84b16fb81a13119e (diff)
Fixed #36267 -- Fixed contenttypes shortcut() view crash with an invalid object_id for a UUIDField pk.
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/models.py8
-rw-r--r--tests/contenttypes_tests/test_views.py10
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/contenttypes_tests/models.py b/tests/contenttypes_tests/models.py
index 5e40217c30..90a928fc2f 100644
--- a/tests/contenttypes_tests/models.py
+++ b/tests/contenttypes_tests/models.py
@@ -1,3 +1,4 @@
+import uuid
from urllib.parse import quote
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
@@ -112,3 +113,10 @@ class ModelWithM2MToSite(models.Model):
def get_absolute_url(self):
return "/title/%s/" % quote(self.title)
+
+
+class UUIDModel(models.Model):
+ id = models.UUIDField(primary_key=True, default=uuid.uuid4)
+
+ def get_absolute_url(self):
+ return "/uuid/%s/" % self.pk
diff --git a/tests/contenttypes_tests/test_views.py b/tests/contenttypes_tests/test_views.py
index 75f39a7bab..8cc11de3cb 100644
--- a/tests/contenttypes_tests/test_views.py
+++ b/tests/contenttypes_tests/test_views.py
@@ -19,6 +19,7 @@ from .models import (
SchemeIncludedURL,
)
from .models import Site as MockSite
+from .models import UUIDModel
@override_settings(ROOT_URLCONF="contenttypes_tests.urls")
@@ -263,3 +264,12 @@ class ShortcutViewTests(TestCase):
obj = FooWithBrokenAbsoluteUrl.objects.create(name="john")
with self.assertRaises(AttributeError):
shortcut(self.request, user_ct.id, obj.id)
+
+ def test_invalid_uuid_pk_raises_404(self):
+ content_type = ContentType.objects.get_for_model(UUIDModel)
+ invalid_uuid = "1234-zzzz-5678-0000-invaliduuid"
+ with self.assertRaisesMessage(
+ Http404,
+ f"Content type {content_type.id} object {invalid_uuid} doesn’t exist",
+ ):
+ shortcut(self.request, content_type.id, invalid_uuid)