Skip to content

KeyError: 'Class JSONField not found in lookup.' #19

Description

@martin-san03

I'm not sure is related to this library, but maybe you can help me.

I'm using to_jsonschema on a rest_framework.serializers.ModelSerializer and I have this error:

    'json_schema': to_jsonschema(serializer_instance)
  File "c:\Private\ai\crackit\.venv\lib\site-packages\drf_jsonschema_serializer\convert.py", line 38, in to_jsonschema
    sub_schema = field_to_jsonschema(field)
  File "c:\Private\ai\crackit\.venv\lib\site-packages\drf_jsonschema_serializer\convert.py", line 23, in field_to_jsonschema
    converter = field_to_converter[field]
  File "c:\Private\ai\crackit\.venv\lib\site-packages\rest_framework\utils\field_mapping.py", line 40, in __getitem__
    raise KeyError('Class %s not found in lookup.' % base_class.__name__)
KeyError: 'Class JSONField not found in lookup.'

I have debugged the code and it seems is ussing rest_framework.serializers.ModelSerializer.serializer_field_mapping

Which has this particular If to add JSONField to the mapping:

        ...
        models.SlugField: SlugField,
        models.SmallIntegerField: IntegerField,
        models.TextField: CharField,
        models.TimeField: TimeField,
        models.URLField: URLField,
        models.UUIDField: UUIDField,
        models.GenericIPAddressField: IPAddressField,
        models.FilePathField: FilePathField,
    }
    if hasattr(models, 'JSONField'):
        serializer_field_mapping[models.JSONField] = JSONField

Does someone known why I have this error?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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