Opened 18 years ago

Closed 16 years ago

#2434 closed defect (wontfix)

[patch] KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW

Reported by: chengqi@… Owned by: nobody
Component: Core (Other) Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Description

  • Because there is a bug here ticket2424, so I've to custom manipulators to save objects with editinlie issues.
  • Then there is another bug here:
    • when using default manipulators to save objects together with edit_inline objects, if I want to suppress one field of the related objects, I have to use follow keywords(right?), then it always throw KeyError.
    • e.g, take the model(Poll/Choice) in django's tutorial1, if want to suppress the 'votes' field of each Choice object when saving a poll, I should use Poll.AddManipulator(follow={'choice': {'votes': False}}), then it will thrown KeyError of 'choice.0.vote' not found while rending the templates.
    • It is the django/forms/init__.py:InlineObjectCollection class that lead to the error. Because I have suppressed the votes field in the manipulaor, so there are no votes fields in the manipulator. But the InlineObjectCollection doesn't refer to the follow parameters, it just loop over all the editable fields. So the bug is encountered.
    • The followings are my codes and my patch.

Codes

Model

from django.db import models

class Poll(models.Model):
    question = models.CharField(maxlength=200)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(maxlength=200)
    votes = models.IntegerField()
    field_to_suppress = models.IntegetField()

View

def view(request):
    ...
    manipulator = Poll.AddManipulator(follow={'choice': {'field_to_suppress': False}})
    ....
    form = forms.FormWrapper(manipulator, new_data, errors)
    c_ = template.RequestContext(request, {
        'form': form
        })
    return render_to_response('templates.html', c_)

templates

...
{% for choice_ in form.choices %}
  {{ choice.votes }}
  {{ choice.choice }}
{% endfor %}
...

Steps to reproduce

  • Try to add a Poll
  • Then the line {% for choice_ in form.choices %} will throw errors of 'Key choice.0.field_to_suppress not found in ..'

Attachments (1)

manipulator_editinline_follow.patch (734 bytes ) - added by anonymous 18 years ago.

Download all attachments as: .zip

Change History (10)

by anonymous, 18 years ago

comment:1 by anonymous, 18 years ago

Summary: InlineObjectCollection error when editinline objects using default AddManipulators with FOLLOWKeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW

comment:2 by Gary Wilson <gary.wilson@…>, 18 years ago

milestone: Version 0.93Version 1.0

0.93 has come and gone.

comment:3 by mail@…, 18 years ago

i've also noticed this bug, the patch fixes it nicely. can it be accepted?

comment:4 by anonymous, 18 years ago

Summary: KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW[patch] KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW

comment:5 by (none), 18 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:6 by Gary Wilson <gary.wilson@…>, 18 years ago

Component: Template systemCore framework
Needs tests: set
Triage Stage: UnreviewedAccepted

comment:7 by Gary Wilson <gary.wilson@…>, 18 years ago

see also #1603.

comment:8 by Adrian Holovaty, 18 years ago

Version: magic-removalSVN

comment:9 by Malcolm Tredinnick, 16 years ago

Resolution: wontfix
Status: newclosed

Since add- and change-manipulators are deprecated and slated for removal in the near future (they're oldforms-related), this isn't something that needs fixing now. Or, rather, it's been fixed by improving the infrastructure.

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