Page 1 of 1

Internal server error when allow_multiple is set to False

Posted: Mon Feb 10, 2020 9:38 am
by rosario.dandrea
Hi,

I'm trying to add a new step in the "upload new document" wizard.

I get the following exception:

Code: Select all

wizard_step.py", line 121, in done
    force_text(order.pk) for order in cleaned_data['orders']
TypeError: 'Order' object is not iterable
The code for wizard_step is the following:

Code: Select all

@classmethod
    def done(cls, wizard):
        result = {}
        cleaned_data = wizard.get_cleaned_data_for_step(cls.name)
        if cleaned_data:
            result['offers'] = [
                force_text(offer.pk) for offer in cleaned_data['offers']
            ]

        return result

The issue happens only when when "allow_multiple" is False in forms.py.

Code: Select all

allow_multiple = False
        field_name = 'orders'
        label = _('Orders')
        required = False
        widget_attributes = {'class':'select2'}
I've tried looking around in the codebase to see if there were any other apps using allow_multiple as False, but I can't find any.

Since the behaviour is untested, this might be a bug. Could someone please look into it?
I've posted here before opening a bug report on GitLab since I'm not 100% sure this might depend on allow_multiple being set to False.

Thanks!

Best Regards,
Rosario

Re: Internal server error when allow_multiple is set to False

Posted: Thu Feb 13, 2020 2:59 am
by rosarior
Hi,

If you set

Code: Select all

allow_multiple = False
the field and the widget will be a single entry element. This means you will not get a QuerySet instance as your code is expecting but a single Model instance.

The code should be:

Code: Select all

result['offers'] = cleaned_data['offers']

Re: Internal server error when allow_multiple is set to False

Posted: Thu Feb 13, 2020 4:10 pm
by rosario.dandrea
Hi Rosario,

Thanks as usual - everything is working now.

Now I just need to get this other thing working...