django-multiselectfield icon indicating copy to clipboard operation
django-multiselectfield copied to clipboard

Fixed IndexError with Django 4.1

Open macmichael01 opened this issue 2 years ago • 9 comments

Fix for issue #131.

macmichael01 avatar Aug 09 '22 14:08 macmichael01

Great job!

dennybiasiolli avatar Aug 17 '22 13:08 dennybiasiolli

Nice ! Do you know if this project is actively maintained anymore ? When could we expect a release compatible with 4.1 ?

Thank you very much for your work 👍

girardinsamuel avatar Aug 31 '22 09:08 girardinsamuel

We might need to ask @goinnn if the project is actively maintained or if he needs help maintaining it 😉

dennybiasiolli avatar Aug 31 '22 09:08 dennybiasiolli

Hi! @macmichael01! I have the same stopper to migrate my application to 4.1.1 version, The way that I could resolve without this change was add max_length as parameter, some like this: MultiSelectField(max_length=100.... The value that you assign in max_length doesnt care because inside the code it will be replaced.

Now I have a suggenstion. Whay do you think if it assigns the max _length in the kwargs dictionary before to call super() method? It leave the responsability to assign this value in django field class:

This is the line where django assigns that validation: https://github.com/django/django/blob/main/django/db/models/fields/init.py#L1119

The code can look like:

def __init__(self, *args, **kwargs):
    self.min_choices = kwargs.pop('min_choices', None)
    self.max_choices = kwargs.pop('max_choices', None)
    choices = kwargs.get('kwargs', None)
    kwargs.update({'max_length': get_max_length(choices, None)})
    super(MultiSelectField, self).__init__(*args, **kwargs)
    if self.min_choices is not None:
        self.validators.append(MinChoicesValidator(self.min_choices))
    if self.max_choices is not None:
        self.validators.append(MaxChoicesValidator(self.max_choices))

Fabfm4 avatar Sep 26 '22 19:09 Fabfm4

@macmichael01 Any chance this can get reviewed and merged?

Afani97 avatar Oct 27 '22 04:10 Afani97

Please merge this PR and release the bug fix

sar009 avatar Nov 10 '22 14:11 sar009

@macmichael01 @goinnn please merge the PR. We have to do some Django upgrades and the plugin is blocking us.

sar009 avatar Nov 24 '22 20:11 sar009

Does this need the condition that it is only appended if there are no other validators declared? Or would simply just appending it be a bit better so that it doesn't get left out.

clhVEGAS avatar Jan 08 '23 15:01 clhVEGAS

still experiencing this issue:)

sewagodimo avatar Jun 11 '23 13:06 sewagodimo

Fixed in #148.

blag avatar May 23 '24 22:05 blag