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

Component re-registration warning when two paginated list endpoints use the same serializer #233

Closed
Lucidiot opened this issue Dec 16, 2020 · 7 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@Lucidiot
Copy link

Describe the bug

When two or more paginated list endpoints use the same response serializers, a warning appears when generating the schema:

Warning #0: trying to re-register a schemas component with name PaginatedFooList. this might lead to a incorrect schema. Look out for reused names

To Reproduce

Create two list endpoints with the same serializer, and set a default pagination class in the settings (or add one in pagination_class on each endpoint).

class FirstList(ListAPIView):
    serializer_class = FooSerializer
    ...

class SecondList(ListAPIView):
    serializer_class = FooSerializer
    ...

Expected behavior

The same component gets reused without a warning.

Maybe this check could be modified to not warn when the two components are the same, not just by key? Or should this part check whether the exact same component already exists before registering?

@tfranzel tfranzel added the bug Something isn't working label Dec 16, 2020
@tfranzel
Copy link
Owner

hey @Lucidiot, yes that looks like a bug. the warning is unwarranted in most circumstances. i'll refine that spot to catch problems and not emit false positives.

@tfranzel tfranzel added the fix confirmation pending issue has been fixed and confirmation from issue reporter is pending label Dec 19, 2020
@tfranzel
Copy link
Owner

that should do it. please confirm and close the issue

@ShaheedHaque
Copy link

I'm not sure if you would consider this the same issue, but (using the 0.12.0 release), I see this:

Warning #0: Encountered 2 components with identical names "PaginatedEmployeeList" and different classes <class 'api.employee.EmployeeSerializer'> and <class 'rest_framework.serializers.ListSerializer'>. This will very likely result in an incorrect schema. Try renaming one.

even though the ListSerializer (implicitly, via many=True) specifies the EmployeeSerializer as its child:

@extend_schema_view(
    ...
    employees=extend_schema(..., responses={HTTP_200_OK: EmployeeSerializer(many=True)}),
    ...
)

Or perhaps I am not using extend_schema as expected?

@tfranzel
Copy link
Owner

hey @ShaheedHaque, i think you are doing it right and i missed a case. the test case did only cover multiple viewsets and not actions. i can see how this happened. i'll investigate. the schema however should still be correct i believe.

@tfranzel
Copy link
Owner

@ShaheedHaque i extended the test. should now behave as expected. schema was unaffected, only a false positive warning.

@ShaheedHaque
Copy link

ShaheedHaque commented Dec 20, 2020 via email

@Lucidiot
Copy link
Author

Lucidiot commented Jan 7, 2021

Just updated and I no longer see any warnings. Thank you very much!

@Lucidiot Lucidiot closed this as completed Jan 7, 2021
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

3 participants