Django

Code

Ticket #2434 (closed: wontfix)

Opened 2 years ago

Last modified 5 months ago

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

Reported by: chengqi@exoweb.net Assigned to: nobody
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

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

manipulator_editinline_follow.patch (0.7 kB) - added by anonymous on 07/27/06 01:30:11.

Change History

07/27/06 01:30:11 changed by anonymous

  • attachment manipulator_editinline_follow.patch added.

07/27/06 01:33:51 changed 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.

08/13/06 00:37:13 changed by Gary Wilson <gary.wilson@gmail.com>

  • milestone changed from Version 0.93 to Version 1.0.

0.93 has come and gone.

09/09/06 12:04:55 changed by mail@jamiehillman.co.uk

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

09/27/06 23:02:07 changed 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.

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted

02/17/07 22:28:24 changed by Gary Wilson <gary.wilson@gmail.com>

  • component changed from Template system to Core framework.
  • needs_tests set to 1.
  • stage changed from Unreviewed to Accepted.

02/17/07 22:34:15 changed by Gary Wilson <gary.wilson@gmail.com>

see also #1603.

06/07/07 16:57:27 changed by adrian

  • version changed from magic-removal to SVN.

07/05/08 21:09:18 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to wontfix.

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.


Add/Change #2434 ([patch] KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW)




Change Properties
Action