Full definitons of swagger responses are possibly being replaced with brief definitions due to nested serializers #9876

Closed
opened 2025-12-29 21:23:52 +01:00 by adam · 3 comments
Owner

Originally created by @deathbeam on GitHub (Jun 20, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.3

Python Version

3.11

Steps to Reproduce

Check swagger JSON, all model representations of responses are only using brief definitions.

Expected Behavior

Swagger responses should always match real responses.

Observed Behavior

Brief representations are being returned, making it effectivelly impossible to use the swagger json.

Originally created by @deathbeam on GitHub (Jun 20, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.3 ### Python Version 3.11 ### Steps to Reproduce Check swagger JSON, all model representations of responses are only using `brief` definitions. ### Expected Behavior Swagger responses should `always` match real responses. ### Observed Behavior Brief representations are being returned, making it effectivelly impossible to use the swagger json.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:23:52 +01:00
adam closed this issue 2025-12-29 21:23:52 +01:00
Author
Owner

@deathbeam commented on GitHub (Jun 20, 2024):

As a side note, most likely caused by this change https://github.com/netbox-community/netbox/pull/15281 by @jeremystretch as im assuming that the generated model response is simply being replaced with nested definition of the same name.

@deathbeam commented on GitHub (Jun 20, 2024): As a side note, most likely caused by this change https://github.com/netbox-community/netbox/pull/15281 by @jeremystretch as im assuming that the generated model response is simply being replaced with nested definition of the same name.
Author
Owner

@deathbeam commented on GitHub (Jun 20, 2024):

As "workaround" deleting

        if self.nested and not fields:
            self._requested_fields = getattr(self.Meta, 'brief_fields', None)

in serializers/base.py

allows at least somewhat coherent swagger output but downside is that it also misrepresents the original nested field values that were correct with the brief representations

@deathbeam commented on GitHub (Jun 20, 2024): As "workaround" deleting ```python if self.nested and not fields: self._requested_fields = getattr(self.Meta, 'brief_fields', None) ``` in serializers/base.py allows at least somewhat coherent swagger output but downside is that it also misrepresents the original nested field values that were correct with the brief representations
Author
Owner

@arthanson commented on GitHub (Jul 12, 2024):

What's happening is the nested=True serializer is getting instantiated first and it looks like Spectacular is caching the fields from this call and using that. So it is hit or miss depending if the full serializer or the nested serializer is getting hit first. I was able to see this in #16765 as nested=True serializer is getting instantiated first in CircuitSerializer for ProviderAccount - if you comment out the nested serializer in CircuitSerializer then ProviderAccount will show correctly in the API browser.

Wondering if we need to do a proxy class on the serializers to bring back NestedSerializers and just have them set the fields.

@arthanson commented on GitHub (Jul 12, 2024): What's happening is the nested=True serializer is getting instantiated first and it looks like Spectacular is caching the fields from this call and using that. So it is hit or miss depending if the full serializer or the nested serializer is getting hit first. I was able to see this in #16765 as nested=True serializer is getting instantiated first in CircuitSerializer for ProviderAccount - if you comment out the nested serializer in CircuitSerializer then ProviderAccount will show correctly in the API browser. Wondering if we need to do a proxy class on the serializers to bring back NestedSerializers and just have them set the fields.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9876