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

@extend_schema_serializer not isolated properly. #585

Closed
ngnpope opened this issue Oct 22, 2021 · 2 comments
Closed

@extend_schema_serializer not isolated properly. #585

ngnpope opened this issue Oct 22, 2021 · 2 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@ngnpope
Copy link
Contributor

ngnpope commented Oct 22, 2021

Hi @tfranzel. This is an extension of the issue in #218 / #554.

Describe the bug

Using @extend_schema_serializer on a class and its subclass causes the subclass to overwrite configuration in the parent. It is likely that this affects all code using set_override(), so also @extend_schema_field also.

To Reproduce

def test_extend_schema_serializer_isolation(no_warnings):
    @extend_schema_serializer(component_name='ABC')
    class OneSerializer(serializers.Serializer):
        pass

    @extend_schema_serializer(component_name='XYZ')
    class TwoSerializer(OneSerializer):
        pass

    assert OneSerializer._spectacular_annotation == {'component_name': 'ABC'}
    assert TwoSerializer._spectacular_annotation == {'component_name': 'XYZ'}

Expected behavior

It seems that set_override() should check to ensure that _spectacular_annotation is cloned to the current class.

@tfranzel
Copy link
Owner

hey @ngnpope, absolutely! Basically the same root cause as with the other issues. Fortunately this time it's a lot less complicated. We simply need to check if the annotation is derived or belongs to the class itself (__dict__) and make a copy.

Hopefully this was the last isolation issue. 😅

@tfranzel tfranzel added bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Oct 23, 2021
@ngnpope
Copy link
Contributor Author

ngnpope commented Nov 9, 2021

Sorry for the delay getting back to you. The fix seems to work nicely. Thanks! 😄

Hopefully this was the last isolation issue. 😅

🤞🏻

@ngnpope ngnpope closed this as completed Nov 9, 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

2 participants