[PR #16627] [MERGED] Fixes #16624: Set allow_null=True on method fields that can return None #14868

Closed
opened 2025-12-29 23:27:11 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/16627
Author: @fabi125
Created: 6/17/2024
Status: Merged
Merged: 7/12/2024
Merged by: @jeremystretch

Base: developHead: nb16624


📝 Commits (1)

  • 4e297ac Fixes #16624: Set allow_null=True on method fields that can return None

📊 Changes

4 files changed (+5 additions, -5 deletions)

View changed files

📝 netbox/dcim/api/serializers_/base.py (+2 -2)
📝 netbox/dcim/api/serializers_/cables.py (+1 -1)
📝 netbox/dcim/api/serializers_/devices.py (+1 -1)
📝 netbox/extras/api/serializers_/scripts.py (+1 -1)

📄 Description

Fixes: #16624

Noticed that Device.parent_device was not marked as nullable in the swagger api docs. Went through all uses of SerializerMethodField and added allow_null=True if the method could return None.

I opted to add it to the @extend_schema_field decorator where possible because that's how allow_null was set on other methods that could return None.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/16627 **Author:** [@fabi125](https://github.com/fabi125) **Created:** 6/17/2024 **Status:** ✅ Merged **Merged:** 7/12/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `nb16624` --- ### 📝 Commits (1) - [`4e297ac`](https://github.com/netbox-community/netbox/commit/4e297ac8dcbd518e9c40520bb8ac1beed5e11bbb) Fixes #16624: Set allow_null=True on method fields that can return None ### 📊 Changes **4 files changed** (+5 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/api/serializers_/base.py` (+2 -2) 📝 `netbox/dcim/api/serializers_/cables.py` (+1 -1) 📝 `netbox/dcim/api/serializers_/devices.py` (+1 -1) 📝 `netbox/extras/api/serializers_/scripts.py` (+1 -1) </details> ### 📄 Description ### Fixes: #16624 Noticed that Device.parent_device was not marked as nullable in the swagger api docs. Went through all uses of `SerializerMethodField` and added `allow_null=True` if the method could return `None`. I opted to add it to the `@extend_schema_field` decorator where possible because that's how `allow_null` was set on other methods that could return `None`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:27:11 +01:00
adam closed this issue 2025-12-29 23:27:11 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14868