﻿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
18153	Erorneous OneToOneField for instances that have pk unset	jbzdak@…	Aymeric Augustin	"Basically if one uses reverse relation for `OneToOneField` from instance that has `pk` unset it results `MultipleObjectsReturned` error, because django serches database for rows that have `NULL` inside `OneToOne` column. For example: 

{{{
class Move(models.Model):
    (...)
    return_move = models.OneToOneField(""self"", related_name=""forward_move"", blank=True, null=True)

    objects = models.GeoManager()
}}}

Then when I use `forward_move` attibute from `move` instance that has no `pk` assigned i get error: 

{{{

m = Move()
m.forward_move
MultipleObjectsReturned at /move/add/ get() returned more than one Move -- it returned 87! Lookup parameters were {'return_move__pk': None}

}}}

There are 87 rows in the database that have `NULL` in `return_move` column.

Desired behaviour is for forward_move to return None --- since instance that is not saved in the databsae cant be referenced by models inside the database. 

I use django 1.4, postgresql database and postgis. 

"	Bug	closed	Database layer (models, ORM)	1.4	Normal	fixed			Accepted	1	0	0	1	0	0
