Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2846 closed defect (worksforme)

something wrong in manipulators

Reported by: fiorix@… Owned by: adrian
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: UI/UX:

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?

Attachments (0)

Change History (1)

comment:1 Changed 8 years ago by ubernostrum

  • Resolution set to worksforme
  • Status changed from new to closed

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

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

should be fine.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.