Opened 9 years ago

Closed 7 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: master
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

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 9 years ago.

Download all attachments as: .zip

Change History (10)

Changed 9 years ago by anonymous

comment:1 Changed 9 years ago by anonymous

  • Summary changed from InlineObjectCollection error when editinline objects using default AddManipulators with FOLLOW to KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW

comment:2 Changed 9 years ago by Gary Wilson <gary.wilson@…>

  • milestone changed from Version 0.93 to Version 1.0

0.93 has come and gone.

comment:3 Changed 9 years ago by mail@…

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

comment:4 Changed 9 years ago by anonymous

  • Summary changed from KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW to [patch] KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW

comment:5 Changed 8 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

comment:6 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Component changed from Template system to Core framework
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

comment:7 Changed 8 years ago by Gary Wilson <gary.wilson@…>

see also #1603.

comment:8 Changed 8 years ago by adrian

  • Version changed from magic-removal to SVN

comment:9 Changed 7 years ago by mtredinnick

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

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