Code

#20323 closed Bug (needsinfo)

BaseFormsetSet.total_form_count seems to ignore absolute_maximum/MAX_NUM_FORM_COUNT once form is bound

Reported by: dpn Owned by: nobody
Component: Forms Version: 1.5
Severity: Normal Keywords:
Cc: dpn@…, bmispelon@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This can be observed in the admin with an inline that has more than 1000 rows (1000 being the default absolute_maximum). It won't save because the range of forms generated is populated from the value of TOTAL_FORMS not MAX_NUM_FORM_COUNT.

The following code seems to fix it. I'm not 100% sure its the right approach though. Happy to jig up something with tests once we know the right approach!

def total_form_count(self):

"""Returns the total number of forms in this FormSet."""
if self.is_bound:

return self.management_form.cleaned_data[MAX_NUM_FORM_COUNT]

Attachments (0)

Change History (2)

comment:1 Changed 12 months ago by dpn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.4 to 1.5

comment:2 Changed 10 months ago by bmispelon

  • Cc bmispelon@… added
  • Resolution set to needsinfo
  • Status changed from new to closed

Hi,

I don't really understand the problem you're describing (if you try to save more forms than allowed by absolute_max, then it's expected that you get an error, no?).
Would it be possible to provide a piece of code that demonstrates the issue?

Secondly, your proposed change doesn't seem right: MAX_NUM_FORM_COUNT is not the same as total_form_count.
In any case, the behavior of total_form_count changed with commit f9ab543720532400e8b0d490cdbe67ea09ae9c17 (this change addressed a potential security issue), so the approach needs to be different.

I'll mark this ticket as needsinfo. Please re-open it with some more details that can help us reproduce the issue.

Thanks.

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.