Opened 5 years ago

Closed 5 years ago

#20996 closed Uncategorized (invalid)

formset factories override any supplied formset max_num

Reported by: Keryn Knight <django@…> Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Because of the way formset_factory yields a new object based on a given formset argument, during which it manually sets some attrs on the resulting object, it is impossible for the following to work:

class MyFormset(BaseFormSet):
    def _max_num(self):
        return 9000 # or whatever
    max_num = property(_max_num)

FromFactory = formset_factory(MyForm, formset=MyFormset)
FromFactory.max_num # will be 1000
FromFactory.max_num = FromFactory._max_num()
FromFactory.max_num # will be 9000

It seems inconsiderate for the factory to override the max_num regardless of what the FormSet says is ok, silently.

I've left it uncategorized, because I can see the argument for the way it behaves currently [especially WRT backwards compatibility], but if it's not fixed, it may be worth finding a place in the documentation [docstrings and/or real docs] to indicate the behaviour.

Change History (1)

comment:1 Changed 5 years ago by polmuz

Resolution: invalid
Status: newclosed

Hi Keryn,

I've been searching the docs looking for a reference of a max_num attribute in formsets and I didn't find it, so it might be an internal attribute.

I did find some documentation on how to change the max_num for a formset using formset_factory, so at least that way of doing things is documented.

This is the code that handles the max_num setting

I'm going to set this as invalid given that there is documentation regarding how to change max_num and setting a max_num directly seems to be dealing with an internal API.

But please, if you consider that honoring the formset max_num attribute is an API worth having, reopen this ticket to discuss it a little better. And if you could provide a patch for that feature that would be awesome too.


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