Some NullBooleanFields Are Documented as Integers #3473

Closed
opened 2025-12-29 18:29:24 +01:00 by adam · 5 comments
Owner

Originally created by @dstarner on GitHub (Mar 12, 2020).

Originally assigned to: @kobayashi on GitHub.

Change Type

[ ] Addition
[X] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

Area

[ ] Installation instructions
[ ] Configuration parameters
[ ] Functionality/features
[X] REST API
[ ] Administration/development
[ ] Other

Proposed Changes

Im not sure if this is a NetBox or lower issue, maybe in drf-yasg, but the Swagger documentation is listing certain NullBooleanFields as integers. This is causing issues when it comes to generation swagger clients because then it tries to marshal a boolean into an int variable, which inevitably explodes. These should be listed as a nullable boolean.

Screen Shot 2020-03-12 at 1 23 16 PM
Originally created by @dstarner on GitHub (Mar 12, 2020). Originally assigned to: @kobayashi on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. Please indicate the nature of the change by placing an X in one of the boxes below. --> ### Change Type [ ] Addition [X] Correction [ ] Deprecation [ ] Cleanup (formatting, typos, etc.) ### Area [ ] Installation instructions [ ] Configuration parameters [ ] Functionality/features [X] REST API [ ] Administration/development [ ] Other <!-- Describe the proposed change(s). --> ### Proposed Changes Im not sure if this is a NetBox or lower issue, maybe in [drf-yasg](https://github.com/axnsan12/drf-yasg/), but the Swagger documentation is listing certain `NullBooleanField`s as integers. This is causing issues when it comes to generation swagger clients because then it tries to marshal a boolean into an `int` variable, which inevitably explodes. These should be listed as a nullable boolean. <img width="667" alt="Screen Shot 2020-03-12 at 1 23 16 PM" src="https://user-images.githubusercontent.com/10478871/76548397-082f1800-6465-11ea-88f2-e5c93495f64c.png">
adam added the type: bug label 2025-12-29 18:29:24 +01:00
adam closed this issue 2025-12-29 18:29:24 +01:00
Author
Owner

@kobayashi commented on GitHub (Mar 16, 2020):

Could you let us know which exact fields should be NullBooleanFields?

@kobayashi commented on GitHub (Mar 16, 2020): Could you let us know which exact fields should be `NullBooleanFields`?
Author
Owner

@stale[bot] commented on GitHub (Mar 30, 2020):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Mar 30, 2020): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@dstarner commented on GitHub (Apr 6, 2020):

Sorry @kobayashi I didn't see your comment. It appears to be anything that extends from ConnectedEndpointSerializer

@dstarner commented on GitHub (Apr 6, 2020): Sorry @kobayashi I didn't see your comment. It appears to be anything that extends from [`ConnectedEndpointSerializer`](https://github.com/netbox-community/netbox/blob/62efe0621f710310f9bceb46fd6d27b0d57bfb3c/netbox/dcim/api/serializers.py#L29)
Author
Owner

@dstarner commented on GitHub (Apr 6, 2020):

Also I should mention that I notice this on the associated connection_status field

@dstarner commented on GitHub (Apr 6, 2020): Also I should mention that I notice this on the associated `connection_status` field
Author
Owner

@kobayashi commented on GitHub (Apr 10, 2020):

Thanks to let us know.
I found this is set in the if statement.

e04a5dc81f/netbox/utilities/custom_inspectors.py (L95-L97)

isinstance(bool, int) handles bool as int because bool is subclass of int.

>>> isinstance(False, int)
True
>>> isinstance(True, int)
True

Is there much better way than this? 🤔

if  not isinstance(choice_value[0], bool) and isinstance(choice_value[0], int):
    # Change value_schema for IPAddressFamilyChoices, RackWidthChoices
    value_schema = openapi.Schema(type=openapi.TYPE_INTEGER, enum=choice_value)
@kobayashi commented on GitHub (Apr 10, 2020): Thanks to let us know. I found this is set in the if statement. https://github.com/netbox-community/netbox/blob/e04a5dc81fc41769069609e992699dffe4a3d79f/netbox/utilities/custom_inspectors.py#L95-L97 `isinstance(bool, int)` handles bool as int because `bool` is subclass of `int`. ``` >>> isinstance(False, int) True >>> isinstance(True, int) True ``` Is there much better way than this? :thinking: ``` if not isinstance(choice_value[0], bool) and isinstance(choice_value[0], int): # Change value_schema for IPAddressFamilyChoices, RackWidthChoices value_schema = openapi.Schema(type=openapi.TYPE_INTEGER, enum=choice_value) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3473