Opened 15 years ago

Last modified 7 years ago

#8165 new New feature

When using can_order=True on formset, ordered_forms is not avaible when formset.is_valid() is false

Reported by: James Chua <james_027@…> Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords: formsets
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


IMO ordered_forms attribute needs to be available even then the formset.is_valid() result to false in order to return the formset in order for re-inputting purpose

Change History (14)

comment:1 Changed 15 years ago by James Chua <james_027@…>

The error is

raise AttributeError("'%s' object has no attribute 'ordered_forms'" %

comment:3 Changed 15 years ago by Jacob

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:4 Changed 15 years ago by Brian Rosner

milestone: 1.0post-1.0
Resolution: invalid
Status: newclosed

I talked with Joseph about this. He says that the behavior of ordered_forms is completely intentional to mirror how cleaned_data works. I can't seem to remember exactly what we discussed here James. I apologize. I am going to close for now, but you are welcome to reopen with a specific use-case. At any rate it is a post-1.0 item due to feature freeze and this isn't a bug.

comment:5 Changed 15 years ago by james_027

Resolution: invalid
Status: closedreopened

An specific use-case could be if a page with a number of same forms were submitted and not every forms are valid and needed to return for re-inputting purpose and when it needed to be return with an order needed, ordered_forms should be available in spite of is_valid() is false.

comment:6 Changed 15 years ago by Patrick Kranzlmueller

I absolutely agree with james_027. why should ordered_forms only be available when is_valid() is true. it may be intentional to mirror cleaned_data, but that doesn´t mean it´s a good idea.

comment:7 Changed 15 years ago by Patrick Kranzlmueller

another usecase: ordering edit-inlines should be possible when order_with_respect_to is defined (or when you use a custom formset with can_order=true). in case of an error, the order of the items (edited inline) is obviously wrong.
solving this whole issue would allow for re-ordering edit-inlines.

comment:8 Changed 15 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:10 Changed 14 years ago by Zain Memon

Status: reopenedassigned

comment:11 Changed 14 years ago by dantallis

I believe ticket:11801 addresses this issue, and that ticket includes a patch and tests.

comment:12 Changed 14 years ago by Jacob

Resolution: duplicate
Status: assignedclosed

Dup of #11801.

comment:14 Changed 12 years ago by yakiimo

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

It seems to me that this is not actually resolved in the ticket this is marked as a duplicate of. Could someone tell me why I'm wrong? I'm new with django so I don't want to reopen it unnecessarily.

The other ticket seems to be on a related issue, but in 1.3 ordered_forms are still not available before the form passes is_valid().

In, line 184, within BaseFormSet:

    def _get_ordered_forms(self):
        Returns a list of form in the order specified by the incoming data.
        Raises an AttributeError if ordering is not allowed.
        if not self.is_valid() or not self.can_order:
            raise AttributeError("'%s' object has no attribute 'ordered_forms'" % self.__class__.__name__)

For what it's worth, my use case is that I'd like to have parallel ordering between two formsets through a foreign key. The only two ways I found were through overriding iter or this way. I thought this way seemed more natural since it doesn't require any overrides.

comment:15 Changed 12 years ago by Carl Meyer

Resolution: duplicate
Status: closedreopened
Type: UncategorizedNew feature

Yes, this ticket was incorrectly closed as a duplicate. #11801 addressed a much more edge case: when there is a deleted form that would otherwise have been invalid, but since it is deleted the overall formset is still valid. This ticket is requesting that the ordered_forms attribute should be available unconditionally, even when the formset is actually not valid.

Version 0, edited 12 years ago by Carl Meyer (next)

comment:16 Changed 11 years ago by Aymeric Augustin

Status: reopenednew

comment:17 Changed 9 years ago by Tim Graham

#21592 is a duplicate which has an incomplete patch and some discussion.

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