[PR #16158] [MERGED] 14953 fix serializers when using add_related_count #14792

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/16158
Author: @arthanson
Created: 5/16/2024
Status: Merged
Merged: 5/17/2024
Merged by: @jeremystretch

Base: developHead: 14953-create-serializer


📝 Commits (3)

  • c967b47 14953 fix serializers when using add_related_count
  • accdb69 14953 update comments
  • 8de07a9 Set default=0 for annotated count fields

📊 Changes

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

View changed files

📝 netbox/dcim/api/serializers_/sites.py (+4 -4)
📝 netbox/tenancy/api/serializers_/contacts.py (+1 -1)
📝 netbox/tenancy/api/serializers_/tenants.py (+1 -1)
📝 netbox/wireless/api/serializers_/wirelesslans.py (+1 -1)

📄 Description

Fixes: #14953

This happens as the count fields are set via add_related_count in the view queryset, in create there isn't a record, therefore no count field. On create the count fields would always be zero so can just be set, obviating the need for any DB call. This should only effect create as a PUT or PATCH will cause the field to get set via the queryset, and the counts shouldn't be changed from the PUT or PATCH call as they are for related objects.


🔄 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/16158 **Author:** [@arthanson](https://github.com/arthanson) **Created:** 5/16/2024 **Status:** ✅ Merged **Merged:** 5/17/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `14953-create-serializer` --- ### 📝 Commits (3) - [`c967b47`](https://github.com/netbox-community/netbox/commit/c967b4742e720e79a31ca63d583a4a5c2a09262d) 14953 fix serializers when using add_related_count - [`accdb69`](https://github.com/netbox-community/netbox/commit/accdb69e2e7a2de9e6628a021eeebbb35ee42119) 14953 update comments - [`8de07a9`](https://github.com/netbox-community/netbox/commit/8de07a9b98e0cc9c35e41ee668c354eb2f2c2e02) Set default=0 for annotated count fields ### 📊 Changes **4 files changed** (+7 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/api/serializers_/sites.py` (+4 -4) 📝 `netbox/tenancy/api/serializers_/contacts.py` (+1 -1) 📝 `netbox/tenancy/api/serializers_/tenants.py` (+1 -1) 📝 `netbox/wireless/api/serializers_/wirelesslans.py` (+1 -1) </details> ### 📄 Description ### Fixes: #14953 This happens as the count fields are set via add_related_count in the view queryset, in create there isn't a record, therefore no count field. On create the count fields would always be zero so can just be set, obviating the need for any DB call. This should only effect create as a PUT or PATCH will cause the field to get set via the queryset, and the counts shouldn't be changed from the PUT or PATCH call as they are for related objects. --- <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:26:46 +01:00
adam closed this issue 2025-12-29 23:26:46 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14792