Django MultiSelectField AttributeError: super object has no attribute _get_flatchoices
Replace legacy django-multiselectfield with django-multiselectfield-2 (maintained fork) or use native models.JSONField with choice validation in Django 5.0+.
Root Cause Analysis
This error occurs when running Django 5.0+ with the third-party package django-multiselectfield, because Django 5.0 removed the private internal method Field._get_flatchoices() which django-multiselectfield relied upon.
1. Django 5.0 Core API Refactoring
In Django 5.0, the internal choice-handling methods on model fields were modernized. The deprecated private method _get_flatchoices() was completely removed in favor of Field.flatchoices property.
2. Unmaintained Third-Party Package Dependencies
The original django-multiselectfield package has not had a release in several years and hardcoded calls to super()._get_flatchoices(), causing immediate crashes upon model initialization or migration in Django 5.0.
3. Native JSONField and ArrayField Alternatives
Modern Django provides models.JSONField (across all database backends) and PostgreSQL ArrayField, which natively handle multiple selected values without third-party plugins.
4. Maintained Community Forks
Community forks like django-multiselectfield-2 patch the flatchoices call for full Django 5.0+ compatibility.
Reproduction Code (MCVE)
# Simulating MultiSelectField calling removed _get_flatchoices on Django CharField
class MockDjangoCharField:
choices = [('A', 'Option A'), ('B', 'Option B')]
class MultiSelectField(MockDjangoCharField):
def get_flatchoices(self):
# In Django 5.0+, _get_flatchoices was removed
return getattr(super(), '_get_flatchoices')()
field = MultiSelectField()
field.get_flatchoices()
Solution 1: Use Native Django models.JSONField for Multiple Choices
Store multi-select lists directly in a native JSONField with standard forms validation, avoiding third-party package bugs.
import json
# Native Django model approach with JSONField
record = {'preferences': ['email_alerts', 'sms_notifications']}
print(f'Preferences stored cleanly: {json.dumps(record)}')
Solution 2: Install Compatible Community Fork django-multiselectfield-2
If migrating database schemas is not feasible, install the maintained fork compatible with Django 5.0.
print('In requirements.txt:')
print('# Replace: django-multiselectfield')
print('django-multiselectfield-2>=0.2.0')
A common mistake is monkey-patching models.Field._get_flatchoices = lambda self: self.flatchoices in __init__.py. Monkey patching core Django internals can lead to subtle bugs in migrations and model serialization. Prefer updating dependencies or adopting native JSONField. Edge cases occur with Django admin filters: use forms.MultipleChoiceField with widgets.CheckboxSelectMultiple in admin forms. Contrast this error with django.core.exceptions.ValidationError, which is raised when form submission data contains choices outside the allowed set.