Skip to content

Crash when running generateschema #6553

@aleksanb

Description

@aleksanb

Spun out from #6532 (comment).

I did a quick test locally on our project which uses django_fields amongst other things. I added

    def get_schema_operation_parameters(self, view):
        return [] 

to DjangoFilterSetBackend as suggested, and hit a new issue with generating the schema:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/management/commands/generateschema.py", line 24, in handle
    schema = generator.get_schema(request=None, public=True)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/schemas/generators.py", line 519, in get_schema
    paths = self.get_paths(None if public else request)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/schemas/generators.py", line 506, in get_paths
    operation = view.schema.get_operation(path, method)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/schemas/inspectors.py", line 536, in get_operation
    operation['responses'] = self._get_responses(path, method)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/schemas/inspectors.py", line 791, in _get_responses
    content = self._map_serializer(serializer)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/schemas/inspectors.py", line 728, in _map_serializer
    schema = self._map_field(field)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/schemas/inspectors.py", line 655, in _map_field
    'items': self._map_serializer(field.child)
  File "/Users/.local/share/virtualenvs/app-SIjAPd74/lib/python3.7/site-packages/rest_framework/schemas/inspectors.py", line 721, in _map_serializer
    for field in serializer.fields.values():
AttributeError: 'DateTimeRangeField' object has no attribute 'fields'

so it might have issues with from drf_extra_fields.fields import DateTimeRangeField? Do custom fields need new attributes?

It could be related to our homebrewn permission system which returns different types of serializers from get_serializer dependent on the request user and which object you're trying to access, but that's a wild guess as I haven't looked into the schema generation code that's crashing as of yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions