Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
deathbeam opened this issue Jun 20, 2024 · 3 comments · Fixed by #17078
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@deathbeam
Copy link
Contributor

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.

@deathbeam deathbeam added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Jun 20, 2024
@deathbeam
Copy link
Contributor Author

As a side note, most likely caused by this change #15281 by @jeremystretch as im assuming that the generated model response is simply being replaced with nested definition of the same name.

@deathbeam
Copy link
Contributor Author

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

@DanSheps DanSheps added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: needs triage This issue is awaiting triage by a maintainer labels Jun 21, 2024
@DanSheps DanSheps removed their assignment Jun 21, 2024
@arthanson
Copy link
Collaborator

arthanson commented 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 up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants