#10015: contrib.comments inline on Postgres 8.3 fails to cast integer to text
--------------------------+-------------------------------------------------
 Reporter:  carljm        |       Owner:  nobody    
   Status:  new           |   Milestone:            
Component:  Contrib apps  |     Version:  1.0       
 Keywords:                |       Stage:  Unreviewed
Has_patch:  0             |  
--------------------------+-------------------------------------------------
 (This bug is related to #8554 and #6523).  If you display comments inline
 in the admin like so:

 {{{
 from django.contrib.contenttypes.generic import GenericTabularInline

 class CarrotCommentInline(GenericTabularInline):
     model = CarrotComment
     ct_fk_field = 'object_pk'
     extra = 0
     fields = ('user', 'comment', 'ip_address', 'is_public', 'is_removed')
 }}}

 Postgres 8.3 will raise this error (for content object types with non-text
 primary keys):

 {{{

 Traceback (most recent call last):
   File
 "/home/carljm/src/py/django/django-1.0.x/django/core/servers/basehttp.py",
 line 635, in __call__
     return self.application(environ, start_response)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/core/handlers/wsgi.py",
 line 239, in __call__
     response = self.get_response(request)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/core/handlers/base.py",
 line 128, in get_response
     return self.handle_uncaught_exception(request, resolver, exc_info)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/core/handlers/base.py",
 line 148, in handle_uncaught_exception
     return debug.technical_500_response(request, *exc_info)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/core/handlers/base.py",
 line 86, in get_response
     response = callback(request, *callback_args, **callback_kwargs)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/contrib/admin/sites.py",
 line 157, in root
     return self.model_page(request, *url.split('/', 2))
   File
 "/home/carljm/src/py/django/django-1.0.x/django/views/decorators/cache.py",
 line 44, in _wrapped_view_func
     response = view_func(request, *args, **kwargs)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/contrib/admin/sites.py",
 line 176, in model_page
     return admin_obj(request, rest_of_url)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/contrib/admin/options.py",
 line 197, in __call__
     return self.change_view(request, unquote(url))
   File "/home/carljm/src/py/django/django-1.0.x/django/db/transaction.py",
 line 238, in _commit_on_success
     res = func(*args, **kw)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/contrib/admin/options.py",
 line 592, in change_view
     formset = FormSet(instance=obj)
   File
 
"/home/carljm/src/py/django/django-1.0.x/django/contrib/contenttypes/generic.py",
 line 303, in __init__
     prefix=self.rel_name
   File "/home/carljm/src/py/django/django-1.0.x/django/forms/models.py",
 line 350, in __init__
     defaults['initial'] = [model_to_dict(obj) for obj in
 self.get_queryset()]
   File
 "/home/carljm/src/py/django/django-1.0.x/django/db/models/query.py", line
 185, in _result_iter
     self._fill_cache()
   File
 "/home/carljm/src/py/django/django-1.0.x/django/db/models/query.py", line
 618, in _fill_cache
     self._result_cache.append(self._iter.next())
   File
 "/home/carljm/src/py/django/django-1.0.x/django/db/models/query.py", line
 275, in iterator
     for row in self.query.results_iter():
   File
 "/home/carljm/src/py/django/django-1.0.x/django/db/models/sql/query.py",
 line 206, in results_iter
     for rows in self.execute_sql(MULTI):
   File
 "/home/carljm/src/py/django/django-1.0.x/django/db/models/sql/query.py",
 line 1734, in execute_sql
     cursor.execute(sql, params)
   File
 "/home/carljm/src/py/django/django-1.0.x/django/db/backends/util.py", line
 19, in execute
     return self.cursor.execute(sql, params)
 ProgrammingError: operator does not exist: text = integer
 LINE 1: ...HERE ("carrot_comments_carrotcomment"."object_pk" = 8  AND "...
                                                              ^
 HINT:  No operator matches the given name and argument type(s). You might
 need to add explicit type casts.

 }}}

 This is because contrib.comments uses a text field type for the PK portion
 of its generic foreign key, and Postgres 8.3 does not automatically cast
 an integer to text.

 This same core problem was already worked around once in [8641], which
 fixed #8554.  This case is more difficult to work around, as the offending
 lookup is part of the  BaseGenericInlineFormset code, and we can't just
 add an explicit cast there.  Maybe the object_pk field type could be
 introspected to check if a cast is needed?  Or perhaps there's a more
 appropriate general solution at the PostgreSQL db backend level.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10015>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to