Skip to content

Conversation

@Mte90
Copy link

@Mte90 Mte90 commented Sep 17, 2025

Right now if I set on detail some fields the other are not available in swagger on the put endpoint as example.

This fix the issue showing all the fields.

Right now if I set on detail some fields the other are not available in swagger on the put endpoint as example.
This fix the issue showing all the fields.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the get_serializer_class method to ensure that all fields are available in API endpoints for non-read operations (PUT, POST, PATCH, DELETE) in OpenAPI/Swagger documentation, even when detail views have restricted field sets.

  • Adds logic to override field restrictions for write operations
  • Ensures complete field visibility in Swagger documentation for modification endpoints

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +195 to +196
if self.action not in ["list", "detail", "retrieve"]:
fields_to_use = "__all__"
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic unconditionally overrides fields_to_use for all non-read actions, ignoring the previously calculated field configuration from lines 182-193.

Looking at lines 186-189, the code already handles write operations (create, update, partial_update) by using the detail fields configuration, which is the appropriate behavior. This new code will override that logic and force __all__ fields for these operations.

Additionally, the condition excludes "detail" but not "retrieve", which are typically equivalent actions in DRF. This inconsistency is problematic because:

  1. "retrieve" is the standard DRF action name for getting a single object
  2. "detail" is not a standard DRF action name

This will break the existing field configuration logic for models that define different fields for list and detail views (like SampleModel in the tests). For write operations, this might expose fields that should only be visible in detail views, or force all model fields to be serialized when only a subset was intended.

Suggested change
if self.action not in ["list", "detail", "retrieve"]:
fields_to_use = "__all__"

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the point to show all the fields that are defined in turbodrf @copilot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant