-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Fixed #36267 -- Fixed contenttypes shortcut() view crash with an invalid object_id for a UUIDField pk. #19296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @AhmedNassar7 for picking this up. I left some suggestions
django/contrib/contenttypes/views.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to special case UUIDField in this way here. Such validation is delegated to the ORM and is not at issue here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather, we want to catch the uncaught ValidationError in the same way we are catching ValueError and ObjectDoesNotExist and return a 404
django/contrib/contenttypes/views.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't catch bare Exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
django/contrib/contenttypes/views.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| try: | |
| obj = content_type.get_object_for_this_type(pk=object_id) | |
| except (ObjectDoesNotExist, ValueError, ValidationError): | |
| raise Http404( | |
| _("Content type %(ct_id)s object %(obj_id)s doesn't exist") | |
| % {"ct_id": content_type_id, "obj_id": object_id} | |
| ) | |
| except ContentType.DoesNotExist: | |
| obj = content_type.get_object_for_this_type(pk=object_id) | |
| except (ObjectDoesNotExist, ValueError, ValidationError): |
the try block we already have should do 👍🏾
django/contrib/contenttypes/views.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| _("Content type %(ct_id)s doesn’t exist") % {"ct_id": content_type_id} | |
| _("Content type %(ct_id)s object %(obj_id)s doesn’t exist") | |
| % {"ct_id": content_type_id, "obj_id": object_id} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thank you!
content_type.views.shortcutThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
…lid object_id for a UUIDField pk.
Trac ticket number
ticket-36267
Branch description
Addressed an issue in
content_type.views.shortcut, where passing an invalid UUID to the view results in an unhandledValidationError. This occurs when attempting to access the "View on Site" button in the Django admin panel with an incorrect UUID format.Checklist
mainbranch.