question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Self parameter is None in mutate method

See original GitHub issue

I don’t know, maybe it’s not a bug and problem caused by rx, but i have this mutation

class ExtendedMutation(graphene.Mutation):

    ok = graphene.Boolean()
    code = graphene.Int()
    message = graphene.String()

    def mutate(self, *_, **__):
        return ExtendedMutation()

class UserLogin(ExtendedMutation):
    class Arguments:
        access_token = graphene.String()

    access_token = graphene.String()

    @login_required
    def mutate(self, info, access_token):
        response = client.login(access_token)
        access_token = response.get('data', dict()).get('access_token', None)

        return UserLogin(
            access_token=access_token,
            ok=response.get('ok'),
            code=response.get('code'),
            message=response.get('message')
        )

and wrote such decorator


def login_required(mutation):
    @wraps(mutation)
    def inner(obj, info, **kwargs):
        access_token = request.headers.get('access_token', None)

        print('obj: {}, info; {}, kwargs: {} '.format(obj, info, kwargs))
        if not access_token:
            return obj(
                ok=False, code=401, message='You must login first'
            )
        return mutation(obj, info, **kwargs)
    return inner

I wait for UserLogin object in self argument of mutation method, but it’s equal None. Info is equal ResolveObject. When i wraps mutate method with @classmethod decorator, i got UserLogin login class, info is None and appears third position required argument which is actually is info.

Any ideas?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:19
  • Comments:26 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
henryfjordancommented, Nov 1, 2019

The intended behavior here makes no sense. The point of a library like graphene is fit some abstraction like graphql into the domain of python. When you ignore the conventions of the target domain (namely python’s use of self on methods in classes), you have failed to make a good library.

If I wanted the function signatures to be exactly the same as Apollo, I’d use Apollo.

Please reinstate self on resolve_... methods and Mutation classes

14reactions
vladcalincommented, Oct 4, 2018

I also experience some frustrations with this and I think this is intended. I remember I saw a discussion in another issue related on this and the conclusion was that this design was deliberately implemented like this but I don’t remember the justification and I can’t seem to find the issue right now.

I think this is a very poor design choice as it doesn’t allow any OOP principle to be applied for mutations and queries as I can’t access any method or member. What’s the point of using classes if you can’t use OOP principles anyway?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Closure cannot implicitly capture a mutating self parameter
Capturing an inout parameter, including self in a mutating method, becomes an error in an escapable closure literal, unless the capture is made...
Read more >
Testing Functions that Mutate Values - Computer Science
The function has no return statement; it produces None . This means that when we call the function there is no useful return...
Read more >
ObjectType - Graphene-Python
This parameter is typically used to derive the values for most fields on an ObjectType. The first parameter of a resolver method (parent)...
Read more >
Mutation Tracking - SQLAlchemy 1.4 Documentation
Our new MutableDict type offers a class method Mutable.as_mutable() which we can ... There's no difference in usage when using declarative: ... Parameters:....
Read more >
PEP 484 – Type Hints - Python Enhancement Proposals
If __init__ assumed a return annotation of -> None , would that mean that an argument-less, un-annotated __init__ method should still be type-checked?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found