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

graphene swallows exceptions during data fetching, destroying info about them in the process. #91

Closed
dgoldstein0 opened this issue Jan 27, 2016 · 4 comments

Comments

@dgoldstein0
Copy link

Currently learning graphene the hard way, and I've been trying to get some info out of it via print and, when that didn't work, by raising exceptions. It appears that custom exceptions make the query partly fail (it seems to return None in place of the object that fails and continues going), but do not get bubbled up at all.

For example:

class Query(ObjectType): # everything should be a relay.Node but this, since it's the base of our schema.
    user = Field(User) # current user
    node = relay.NodeField()

    @resolve_only_args
    def resolve_user(self, **args):
        raise Exception(args)
        return User(id=1, user_id=1) # todo

schema = Schema(query=Query, auto_camelcase=False)

with the following test code:

In [8]: res2 = schema.execute("query { user {user_id} }")

In [9]: print res2.errors, res2.invalid, res2.data
[GraphQLError('{}',)] False OrderedDict([('user', None)])

shows that graphql is clearly swallowing custom exceptions, and then returning them as part of errors; doing this appears to lose the stack trace (and also makes sys.exc_info() useless). This makes it impossible to integrate with my usual exception monitoring, since we need either the original exc_info or the ability to report or reraise the original exception when it's first caught. While the query being executed is useful to know about, having the original stack trace is far more valuable and only the "which piece of the query was being executed" is really unique - our exception handling code already handles getting request params for us.

Any of the following solutions would work for me:

  1. don't swallow the exceptions, just raise them; this avoids doing extra work, since we might want to just 500 these failing request anyway to encourage developers to notice & fix them. Maybe could be implemented with a Plugin?
  2. return the exc_info of each exception as part of errors. This seems simplest.
  3. have some sort of on_exception hook availabe that would run within the except block that's currently swallowing these exceptions, that could handle the reporting.
@rafales
Copy link

rafales commented Jan 27, 2016

This bit me too.

@gwind
Copy link

gwind commented Jan 27, 2016

me too.

BTW, some related suggest:

  1. Intergrade with form validate, such as WTForm
  2. field with validate

@syrusakbary
Copy link
Member

You are completely right.
However the problem is caused by graphql-core library.

Related issue: graphql-python/graphql-core#41

I'm going to work to fix ASAP in graphql-core so will not happen anymore on graphene.

@jhgg
Copy link
Member

jhgg commented Jan 27, 2016

Open a PR and I'll review it today!

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

No branches or pull requests

5 participants