﻿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
22210	Saving Model instance to Float Field	hphilip456@…	anonymous	"I came across what I believe to be an undesired behavior.

If we have a model such as: 
{{{
class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    age = models.FloatField()
}}}

Then try to do this:

{{{
obj = Person.objects.get(pk=1)
obj.age = obj
obj.save()
}}}

It will succeed with out throwing any errors. If we then get that same instance back from the database the age of that instance will be one which is the primary key of the object. 

This is clearly a corner case but I think it would be worth hardening django to not allow this behavior to happen. I thought that the get_prep_value() method would have been called which would have thrown a TypeError since you can not cast a model instance to a float. It turns out that this does not happen because django.db.models.sql.compiler.SQLUpdateCompiler.as_sql checks if the value of a field has the attribute 'prepare_database_save' which a model instance does it uses that instead of field.get_db_prep_save.
 "	Bug	closed	Database layer (models, ORM)	1.6	Normal	fixed			Ready for checkin	1	0	0	0	0	0
