﻿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
22292	Problems with updating a ForeignKey having a to_field attribute	sly010	nobody	"class Owner(models.Model):
	uid = models.CharField(max_length = 255, unique = True)

class Article(models.Model):
	owner = models.ForeignKey(Owner, to_field = 'uid')

owner = ...
article = ... 

1
Article.objects.filter(pk = article.pk).update( owner = owner )
# BROKEN
# injects id into the sql instead of uid
# best case fails with integrity error, worst case it silently continues (depends on the content of the tables)

2
Article.objects.filter(pk = article.pk).update( owner = owner.uid )
# WORKS

3
Article.objects.filter(pk = article.pk).update( owner_id = owner.uid )
# FAILS (unrecognized field name)

4
Article.objects.filter(pk = article.pk).update( owner_id = owner )
# FAILS (unrecognized field name)

5
article.owner = owner
article.save(update_field = ['owner'])
# WORKS

6
article.owner = owner.uid
article.save(update_field = ['owner'])
# FAILS

7
article.owner_id = owner.uid
article.save(update_field = ['owner'])
# WORKS

8
article.owner_id = owner
article.save(update_field = ['owner'])
# FAILS

1 and 5 should definitely be working the same way, maybe some pointer as to which one is the preferred way (especially going forward)?"	Bug	closed	Uncategorized	1.6	Normal	duplicate	ForeignKey to_field		Unreviewed	0	0	0	0	0	0
