_count fields in NestedSerializers should be removed #7665

Closed
opened 2025-12-29 20:26:38 +01:00 by adam · 2 comments
Owner

Originally created by @arthanson on GitHub (Feb 21, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.4.4

Python version

3.8

Steps to Reproduce

  1. Setup NetBox with some demo data including a Circuit.
  2. Setup an API Token
  3. Make a REST API Call to circuits:
curl -H "Authorization: Token $TOKEN" -H "Accept: application/json; indent=4" http://127.0.0.1:8000/api/circuits/circuits/

The returned data does not include a circuit_count for Provider:

{
    "count": 29,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 19,
            "url": "http://127.0.0.1:8000/api/circuits/circuits/19/",
            "display": "1002840283",
            "cid": "1002840283",
            "provider": {
                "id": 2,
                "url": "http://127.0.0.1:8000/api/circuits/providers/2/",
                "display": "CenturyLink",
                "name": "CenturyLink",
                "slug": "centurylink"
            },

However if you look at https://github.com/netbox-community/netbox/blob/develop/netbox/circuits/api/nested_serializers.py#L31 the NestedSerializer has circuit_count. The issue is that it isn't appended to the Circuit queryset. This causes issues with OpenAPI schema generation as it is shown as not optional.

Expected Behavior

circuit_count would not be part of the NestedSerializer.

Observed Behavior

circuit_count is included in the NestedSerializer but not in the returned REST data.

Originally created by @arthanson on GitHub (Feb 21, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.4.4 ### Python version 3.8 ### Steps to Reproduce 1. Setup NetBox with some demo data including a Circuit. 2. Setup an API Token 3. Make a REST API Call to circuits: ``` curl -H "Authorization: Token $TOKEN" -H "Accept: application/json; indent=4" http://127.0.0.1:8000/api/circuits/circuits/ ``` The returned data does not include a circuit_count for Provider: ``` { "count": 29, "next": null, "previous": null, "results": [ { "id": 19, "url": "http://127.0.0.1:8000/api/circuits/circuits/19/", "display": "1002840283", "cid": "1002840283", "provider": { "id": 2, "url": "http://127.0.0.1:8000/api/circuits/providers/2/", "display": "CenturyLink", "name": "CenturyLink", "slug": "centurylink" }, ``` However if you look at https://github.com/netbox-community/netbox/blob/develop/netbox/circuits/api/nested_serializers.py#L31 the NestedSerializer has circuit_count. The issue is that it isn't appended to the Circuit queryset. This causes issues with OpenAPI schema generation as it is shown as not optional. ### Expected Behavior circuit_count would not be part of the NestedSerializer. ### Observed Behavior circuit_count is included in the NestedSerializer but not in the returned REST data.
adam added the type: bugstatus: under reviewstatus: blocked labels 2025-12-29 20:26:39 +01:00
adam closed this issue 2025-12-29 20:26:39 +01:00
Author
Owner

@arthanson commented on GitHub (Mar 22, 2023):

I think this is fixed in OpenAPI3, pending blocked by it: #11626

@arthanson commented on GitHub (Mar 22, 2023): I think this is fixed in OpenAPI3, pending blocked by it: #11626
Author
Owner

@arthanson commented on GitHub (Apr 15, 2023):

This looks like it is no longer an issue with OpenAPI3, it circuit_count is no longer includes in the Nested serializer.

@arthanson commented on GitHub (Apr 15, 2023): This looks like it is no longer an issue with OpenAPI3, it circuit_count is no longer includes in the Nested serializer.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7665