﻿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
2846	something wrong in manipulators	fiorix@…	Adrian Holovaty	"I have a Person model like this:

{{{
class Person(models.Model):
  user = OneToOneField(User)
  dept = ForeignKey(Department)
  phone = ...
}}}


Also I have a form for any user change its own account settings. The code is:


{{{
def index(request):
    manip = Person.ChangeManipulator(request.user)
    if request.POST:
        new_data = request.POST.copy()
        errors = manip.get_validation_errors(new_data)

        if not errors:
            manip.do_html2python(new_data)
            manip.save(new_data)
            return HttpResponseRedirect('/tosco/')

    else:
        errors = {}
        new_data = manip.flatten_data()

    form = forms.FormWrapper(manip, new_data, errors)
    return render_to_response('tosco.html', {'form':form})

}}}

When I submit the POST to the form I get an error like this:


{{{
ProgrammingError at /tosco/
ERROR: column ""alec"" does not exist SELECT 1 FROM ""person_person"" WHERE ""user_id""=alec LIMIT 1
}}}



OK. I discovered that the data in new_data is fine, with the id number of the user 'alec'. But when I call manip.save(new_data) it's being changed to the value 'alec' instead of the id number, at /path-to/django/db/models/manipulators.py line 97:

{{{
if self.change:
   params[self.opts.pk.attname] = self.obj_key
}}}


I don't know why this is happening but if I change that to self.obj_key.id it works fine. Is that a bug?"	defect	closed	Core (Other)	0.95	normal	worksforme			Unreviewed	0	0	0	0	0	0
