Closed symphoton closed 4 months ago
This also holds for Django 4.0.
I am seeing the same issue after an upgrade from django 4.0.7 to 4.1.2
Thanks for the workaround.
- Potential workaround for users: explicitly specify max_length in MultiSelectField, this should lead to old behaviour even with Django 4.1 Drawback is that this disables the automatic max_length computation of this packages. Therefore be careful to choose max_lenght big enough
Thanks for that. I just use the get_max_length function for max_length, so the automatic max_length computation still works.
from multiselectfield.utils import get_max_length
from multiselectfield import MultiSelectField
class TestModel(models.Model):
multifield = MultiSelectField(choices=MultiChoices.choices, blank=True, null=True, max_length=get_max_length(MultiChoices.choices, None))
Multi
- Potential workaround for users: explicitly specify max_length in MultiSelectField, this should lead to old behaviour even with Django 4.1 Drawback is that this disables the automatic max_length computation of this packages. Therefore be careful to choose max_lenght big enough
Thanks for that. I just use the get_max_length function for max_length, so the automatic max_length computation still works.
from multiselectfield.utils import get_max_length from multiselectfield import MultiSelectField class TestModel(models.Model): multifield = MultiSelectField(choices=MultiChoices.choices, blank=True, null=True, max_length=get_max_length(MultiChoices.choices, None))
MultiChoices not defined.
@PraveenChordia Set choices
to be a list of options. Usually you'd define a constant in the model class and reference it like so
from multiselectfield import MultiSelectField
from multiselectfield.utils import get_max_length
class TestModel(models.Model):
MULTIFIELD_CHOICES = (
('read', 'Code'),
('you', 'Copy'),
)
multifield = MultiSelectField(
choices=MULTIFIELD_CHOICES,
max_length=get_max_length(MULTIFIELD_CHOICES, None),
)
@goinnn thanks for the great package, but would it be possible to merge #132 so this can work on Django 4.0+?
Django 4.1 support has already ended, but we still test against Django 4.2 and 5.0, and tests are passing. Closing, since I think we fixed this in #148 and elsewhere.
The error message is as follows:
File "*****lib/python3.9/site-packages/multiselectfield/db/fields.py", line 72, in init self.validators[0] = MaxValueMultiFieldValidator(self.max_length) IndexError: list assignment index out of range
Steps to reproduce: Use a MultiSelectField without explicitly specifying max_lenght attribute
Reason for failure is the following django commit: https://github.com/django/django/commit/0ed2919814c80e31626dffdb6b80d0c20d43452f
Obviously, django team realized that always adding a MaxValueFieldValidator if max_lenght is omitted is not a good idea for derived classes (like MultiSelectField) and
Proposed solution:
Potential workaround for users: explicitly specify max_length in MultiSelectField, this should lead to old behaviour even with Django 4.1 Drawback is that this disables the automatic max_length computation of this packages. Therefore be careful to choose max_lenght big enough