Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2846 closed defect (worksforme)

something wrong in manipulators

Reported by: fiorix@… Owned by: Adrian Holovaty
Component: Core (Other) Version: 0.95
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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?

Change History (1)

comment:1 by James Bennett, 18 years ago

Resolution: worksforme
Status: newclosed

ChangeManipulator excepts an object id to be passed to it, not an object; doing

manip = Person.ChangeManipulator(request.user.id)

should be fine.

Note: See TracTickets for help on using tickets.
Back to Top