From a3196dac481410cf6fa7796cfe3b179df2d6a935 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 1 Sep 2008 17:23:09 +0000 Subject: [PATCH] Make sure to use force_unicode when looking up comment objects by `object_pk`. Fixes #8762, and one other bug that nobody's reported yet. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8800 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/comments/forms.py | 3 ++- django/contrib/comments/managers.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/django/contrib/comments/forms.py b/django/contrib/comments/forms.py index adb2741873..58af4466d0 100644 --- a/django/contrib/comments/forms.py +++ b/django/contrib/comments/forms.py @@ -8,6 +8,7 @@ from django.conf import settings from django.http import Http404 from django.contrib.contenttypes.models import ContentType from models import Comment +from django.utils.encoding import force_unicode from django.utils.text import get_text_list from django.utils.translation import ngettext from django.utils.translation import ugettext_lazy as _ @@ -49,7 +50,7 @@ class CommentForm(forms.Form): new = Comment( content_type = ContentType.objects.get_for_model(self.target_object), - object_pk = str(self.target_object._get_pk_val()), + object_pk = force_unicode(self.target_object._get_pk_val()), user_name = self.cleaned_data["name"], user_email = self.cleaned_data["email"], user_url = self.cleaned_data["url"], diff --git a/django/contrib/comments/managers.py b/django/contrib/comments/managers.py index d664fdaca0..a1ac8097da 100644 --- a/django/contrib/comments/managers.py +++ b/django/contrib/comments/managers.py @@ -1,6 +1,7 @@ from django.db import models from django.dispatch import dispatcher from django.contrib.contenttypes.models import ContentType +from django.utils.encoding import force_unicode class CommentManager(models.Manager): @@ -18,5 +19,5 @@ class CommentManager(models.Manager): ct = ContentType.objects.get_for_model(model) qs = self.get_query_set().filter(content_type=ct) if isinstance(model, models.Model): - qs = qs.filter(object_pk=model._get_pk_val()) + qs = qs.filter(object_pk=force_unicode(model._get_pk_val())) return qs