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

Extensions Added Twice When Custom Directives Are Present #3776

Open
doney-dkp opened this issue Feb 11, 2025 · 2 comments
Open

Extensions Added Twice When Custom Directives Are Present #3776

doney-dkp opened this issue Feb 11, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@doney-dkp
Copy link

doney-dkp commented Feb 11, 2025

Describe the Bug
When custom directives are added, extensions are appended twice in the get_extensions function in the schema.py file.

Issue
In the following code:
https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/schema/schema.py
line 299

    def get_extensions(self, sync: bool = False) -> list[SchemaExtension]:
        extensions = []
        if self.directives:
            extensions = [
                *self.extensions,
                DirectivesExtensionSync if sync else DirectivesExtension,
            ]
        extensions.extend(self.extensions)
        return [
            ext if isinstance(ext, SchemaExtension) else ext(execution_context=None)
            for ext in extensions
        ]

The extensions list already contains self.extensions, and then extend(self.extensions) adds them again, causing duplicates.

Example Reproduction

>>> ex = ["a", "b"]
>>> extensions = [*ex]
>>> extensions
['a', 'b']
>>> extensions.extend(ex)
>>> extensions
['a', 'b', 'a', 'b']

Expected Behavior
Extensions should not be duplicated when custom directives are present.

Suggested Fix
Modify the logic to avoid adding self.extensions twice.
remove line extensions.extend(self.extensions)

@doney-dkp doney-dkp added the bug Something isn't working label Feb 11, 2025
@bellini666
Copy link
Member

Hey @doney-dkp ,

nice catch there!

Do you want to try to submit a PR to fix that?

@doney-dkp
Copy link
Author

doney-dkp commented Feb 13, 2025

@bellini666 sure, happy to do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants