10

This error is thrown in django even though it's not even imported anywhere. It's thrown by OpenAPISchemaGenerator as follows:

 File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/drf_yasg/inspectors/field.py", line 406, in <module>
    (serializers.NullBooleanField, (openapi.TYPE_BOOLEAN, None)),
AttributeError: module 'rest_framework.serializers' has no attribute 'NullBooleanField'

How do I fix this? link. It doesn't answer the question.

Prakhar Rathi
  • 905
  • 1
  • 11
  • 25

4 Answers4

14

NullBooleanField was removed in DRF 3.14.0 - see https://github.com/encode/django-rest-framework/pull/8599

Suggest to avoid 3.14.0 unless you can find another way to resolve..

djangorestframework>=3.13.1,!=3.14.0
maharg101
  • 507
  • 4
  • 6
  • 1
    The `NullBooleanField` is deprecated, so you would need to exclude *every* version starting from `3.14` upwards, *not* just `3.14.0`. However, I don't think that would be a proper solution either. – djvg Oct 27 '22 at 11:21
  • A true fix would be to use `BooleanField` instead, [as suggested in the deprecation warning](https://stackoverflow.com/a/74221187). – djvg Oct 27 '22 at 11:23
6

The support for NullBooleanField was removed in 3.14.0. I have raised an issue on the drf-yasg github asking for support for this version of drf. They have also released a PR for this which is yet to be merged.

Prakhar Rathi
  • 905
  • 1
  • 11
  • 25
5

Which drf version do you use? I had the same issue today, changing from djangorestframework = "^3.13.1" to djangorestframework = "3.13.1" solved the issue. I guess today was the release of drf 3.14

Amerlan
  • 51
  • 1
3

drf-yasg version 1.21.4, released Sep 27, fixes this.

FIXED: Remove NullBooleanFields if the django-rest-framework version >= 3.14.0 (#814)

https://github.com/axnsan12/drf-yasg/releases/tag/1.21.4

Roberto Rosario
  • 1,818
  • 1
  • 17
  • 31