Error hit on ArrayField with Choices #8158
Unanswered
brianedelman
asked this question in
Potential Issue
Replies: 1 comment 8 replies
-
the django version is probably 3.1 for the commit |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using choices on an ArrayField, hit an error with DRF serializing.
I have a field defined like this. Preservation.choices consists of TextChoices
preservation = ArrayField( models.CharField(max_length=25, default=Preservation.ICE, null=True,), choices=Preservation.choices, default=list, )
Traceback (most recent call last):
File ".virtualenvs/hle/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 76, in call
return self.application(environ, start_response)
File ".virtualenvs/hle/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 133, in call
response = self.get_response(request)
File ".virtualenvs/hle/lib/python3.7/site-packages/django/core/handlers/base.py", line 130, in get_response
response = self._middleware_chain(request)
File ".virtualenvs/hle/lib/python3.7/site-packages/django/core/handlers/exception.py", line 49, in inner
response = response_for_exception(request, exc)
File ".virtualenvs/hle/lib/python3.7/site-packages/django/core/handlers/exception.py", line 114, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File ".virtualenvs/hle/lib/python3.7/site-packages/django/core/handlers/exception.py", line 149, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File ".virtualenvs/hle/lib/python3.7/site-packages/django_extensions/management/technical_response.py", line 40, in null_technical_500_response
raise exc_value.with_traceback(tb)
File ".virtualenvs/hle/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File ".virtualenvs/hle/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File ".virtualenvs/hle/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File ".virtualenvs/hle/src/djangorestframework/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/mixins.py", line 56, in retrieve
return Response(serializer.data)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 548, in data
ret = super().data
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 246, in data
self._data = self.to_representation(self.instance)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 515, in to_representation
ret[field.field_name] = field.to_representation(attribute)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 664, in to_representation
self.child.to_representation(item) for item in iterable
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 664, in
self.child.to_representation(item) for item in iterable
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 500, in to_representation
for field in fields:
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 361, in _readable_fields
for field in self.fields.values():
File ".virtualenvs/hle/lib/python3.7/site-packages/django/utils/functional.py", line 48, in get
res = instance.dict[self.name] = self.func(instance)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 349, in fields
for key, value in self.get_fields().items():
File ".virtualenvs/hle/src/djangorestframework/rest_framework/serializers.py", line 1063, in get_fields
fields[field_name] = field_class(**field_kwargs)
File ".virtualenvs/hle/src/djangorestframework/rest_framework/fields.py", line 1420, in init
super().init(**kwargs)
TypeError: init() got an unexpected keyword argument 'child'
I used to have the choices on the CharField inside the ArrayField and it worked fine, but the get_FOO_display() method doesn't register for that field.
Beta Was this translation helpful? Give feedback.
All reactions