﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14003	Filtering on a relation whose model has a different PK type doesn't work	David Gouldin	nobody	"Using the following models:

{{{
class Author(models.Model):
    name = models.CharField(max_length=255)

class Book(models.Model):
    name = models.CharField(max_length=50, primary_key=True)
    author = models.ForeignKey(Author)
}}}

The following code fails:

{{{
In [1]: a = Author.objects.create(name='Me')

In [2]: b = Book.objects.create(name='My Book', author=a)

In [3]: Author.objects.filter(book=b)
....
ValueError: invalid literal for int() with base 10: 'My Book'
}}}

This seems to be the source of the problem:

http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py?rev=13037#L190

_pk_trace uses field.rel.to to resolve the field to use for prepping the filter value.  In the case above, It's preparing Book.pk (a CharField) as if it were a value for Author.pk (an AutoField) and blows up when casting the string to an int.  I'm not sure how best to go about solving the issue.  _pk_trace doesn't currently have any way I know of to tell which side of the relation the value arg is coming from."	Bug	closed	Database layer (models, ORM)	1.2	Normal	fixed		dgouldin@…	Accepted	0	0	0	0	0	0
