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

Check callable field sources before execution #228

Merged

Conversation

danbentley
Copy link
Contributor

Firstly thanks for this package! It's helped remove a lot of glue code from a project!

I've spotted some GraphQL queries raising graphql.error.located_error.GraphQLLocatedError: 'str' object is not callable.

I tracked it down to custom_cls_resolver where a check is performed to see whether the block's class has an attribute with the same name as the queried value, to support the grapple.models.GraphQLField(source=<attr-or-method>) functionality.

The block I was querying contained a sub-block bound to name which during resolution, custom_cls_resolver would fetch the name attribute from wagtail.core.blocks.base.Block and attempt to execute it.

This PR adds a check to ensure that any attr is callable before attempting to execute it, allowing queries with blocks bound to name to resolve using the streamfield_resolver.

Fixes queries for values whose name clashes with existing attributes on
the Block's class (such as "name").
Copy link
Member

@zerolab zerolab left a comment

Choose a reason for hiding this comment

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

Thank you for this, @danbentley

LGTM

@zerolab zerolab requested a review from kbayliss June 6, 2022 08:24
@zerolab zerolab merged commit 4e9679b into torchbox:main Jun 7, 2022
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.

2 participants