AttributeError: module 'rest_framework.serializers' has no attribute 'NullBooleanField'
Asked Answered
S

1

7

After upgrading djangorestframework from djangorestframework==3.13.1 to djangorestframework==3.14.0 the code

from rest_framework.serializers import NullBooleanField

Throws

AttributeError: module 'rest_framework.serializers' has no attribute 'NullBooleanField'

Reading the release notes I don't see a deprecation. Where did it go?

Smalltime answered 23/9, 2022 at 6:26 Comment(2)
Aparently it is an issue in drf_spectacular: github.com/tfranzel/drf-spectacular/issues/816 that got fixed with drf-spectacular==0.24.1Smalltime
I've added it to the drf project as a discussion:github.com/encode/django-rest-framework/discussions/8667Smalltime
A
3

For what it's worth, there's a deprecation warning in the previous version, which also suggests a fix:

The NullBooleanField is deprecated and will be removed starting with 3.14. Instead use the BooleanField field and set allow_null=True which does the same thing.

Awesome answered 27/10, 2022 at 11:15 Comment(1)
Side note: Django's NullBooleanField is also removed in Django 4.0Awesome

© 2022 - 2024 — McMap. All rights reserved.