Internal server error when allow_multiple is set to False

Technical aspects, customization, code samples.
Post Reply
rosario.dandrea
Posts: 8
Joined: Fri Jan 31, 2020 9:39 am

Internal server error when allow_multiple is set to False

Post 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

User avatar
rosarior
Developer
Developer
Posts: 505
Joined: Tue Aug 21, 2018 3:28 am
Location: Puerto Rico
Contact:

Re: Internal server error when allow_multiple is set to False

Post 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']

rosario.dandrea
Posts: 8
Joined: Fri Jan 31, 2020 9:39 am

Re: Internal server error when allow_multiple is set to False

Post by rosario.dandrea »

Hi Rosario,

Thanks as usual - everything is working now.

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

Post Reply