﻿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
7823	ForeignKey get_db_prep_lookup doesn't work for custom primary key	Ivan Sagalaev	Malcolm Tredinnick	"If a parent model has a user-defined field as a primary key:

{{{
class Parent(models.Model):
    user_id = CutomUserField(primary_key=True)

class Child(models.Model):
    parent = models.ForeignKey(Parent)
}}}

then this query will fail:

{{{
p = Parent(...)
Child.objects.filter(parent=p)
}}}

This happens because get_db_prep_lookup doesn't get called on p.user_id and its value (which is a custom user class) gets passed as an sql parameter into db.

Patch follows.

P.S. A bug is very practical: we have custom non-model user objects instead of contrib.auth.models.User and can't reference them from models with custom UserField because many queries using those models would break."		closed	Database layer (models, ORM)	dev		fixed			Accepted	1	0	0	0	0	0
