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

PrimaryKeyRelatedField(read_only=True, pk_field=IntegerField()) have incorrect scheme #1335

Closed
MaHryCT3 opened this issue Nov 22, 2024 · 0 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@MaHryCT3
Copy link

MaHryCT3 commented Nov 22, 2024

Describe the bug
I found a couple issues already solved related to this, but not found about pk_field. The problem is related to PrimaryKeyRelatedField(read_only=True). I try to add to this pk_field=IntegerField, but schema field=STR
image

To Reproduce

from drf_spectacular.utils import extend_schema
from rest_framework import serializers
from rest_framework.viewsets import ViewSet
from rest_framework.response import Response


class ResponseSerializer(serializers.Serializer):
    route = serializers.PrimaryKeyRelatedField(
        read_only=True,
        pk_field=serializers.IntegerField(),
    )


class AnalysisRouteSchemeViewSet(ViewSet):

    @extend_schema(
        responses=ResponseSerializer,
    )
    def list(self, *args, **kwargs):
        return Response()

Expected behavior
Schema type taken from pk_field if pk_field defined

Place in code: https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/openapi.py#L712

tfranzel added a commit that referenced this issue Nov 27, 2024
consider pk_field on PrimaryKeyRelatedField when set #1335
@tfranzel tfranzel added bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Nov 27, 2024
@tfranzel tfranzel closed this as completed Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants