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.

TypeError: __init__() got an unexpected keyword argument 'type'

See original GitHub issue

Hi, I am getting a TypeError on importing graphql_compiler.compile_graphql_to_cypher.

Stacktrace

Traceback (most recent call last):
  File "graphql_compiler_redis_test.py", line 6, in <module>
    from graphql_compiler import compile_graphql_to_cypher
  File "/env/lib/python3.6/site-packages/graphql_compiler/__init__.py", line 3, in <module>
    from .compiler import (  # noqa
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/__init__.py", line 2, in <module>
    from .common import (  # noqa
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/common.py", line 4, in <module>
    from . import (
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/emit_cypher.py", line 3, in <module>
    from .blocks import Fold, QueryRoot, Recurse, Traverse
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/blocks.py", line 7, in <module>
    from .helpers import (
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/helpers.py", line 14, in <module>
    from ..schema import INBOUND_EDGE_FIELD_PREFIX, OUTBOUND_EDGE_FIELD_PREFIX, is_vertex_field_name
  File "/env/lib/python3.6/site-packages/graphql_compiler/schema.py", line 26, in <module>
    description='Name of the filter operation to perform.',
TypeError: __init__() got an unexpected keyword argument 'type'

Steps to Reproduce

from graphql_compiler import compile_graphql_to_cypher

System details

Linux: Ubuntu 20.04.1 LTS Python version: 3.6.12 The output of pip list:

Package          Version
---------------- -------
arrow            0.17.0
funcy            1.15
graphql-compiler 1.11.0
graphql-core     2.3.2
pip              20.3.3
promise          2.3
python-dateutil  2.8.1
pytz             2020.5
Rx               1.6.1
setuptools       51.0.0
six              1.15.0
SQLAlchemy       1.3.22
wheel            0.35.1

PS: The python virtual environment had just graphql-compiler installed.

Things I already tried

I tried with python v3.8.5. Got the same error.

I went through this issue https://github.com/kensho-technologies/graphql-compiler/issues/861 and made sure that the package versions are correct, especially graphql-core as mentioned in setup.py

Digging a little more, I found that error points to L26 of graphql_compiler/schema.py. Snippet of code around there is:

FilterDirective = GraphQLDirective(
    name='filter',
    args=OrderedDict([(
        'op_name', GraphQLArgument(
            type=GraphQLNonNull(GraphQLString),
            description='Name of the filter operation to perform.',
        )),
        ('value', GraphQLArgument(
            type=GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLString))),
            description='List of string operands for the operator.',
        ))]
    ),

here you are attempting to create a GraphQLArgument with type=GraphQLNonNull(GraphQLString), but going through the codebase of graphql-core v2.3.2, class GraphQLArgument constructor is this:

class GraphQLArgument(object):
    __slots__ = "type", "default_value", "description", "out_name"

    def __init__(
        self,
        type_,  # type: Union[GraphQLInputObjectType, GraphQLNonNull, GraphQLList, GraphQLScalarType]
        default_value=None,  # type: Optional[Any]
        description=None,  # type: Optional[Any]
        out_name=None,  # type: Optional[str]
    ):
        # type: (...) -> None
        self.type = type_
        self.default_value = default_value
        self.description = description
        self.out_name = out_name

the constructor seems to accept the keyword argument type_ instead of type. So I went through your repo to find over here that this change from type to type_ has already been done.

pip install graphql-compiler installs v1.11.0. Should I explicitly use one of v2.0.0dev versions?

Sorry if this was a lot of info but I hope that it helps in resolving this issue. Looking forward to your reply.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sanchit-gupta-cncommented, Jan 7, 2021

Hi, Thank you for the detailed reply. Will be looking forward to v2 being released.

And yes, your guess was correct. I was trying to use graphql-compiler along with RedisGraph. The main motivation was to avoid writing boilerplate code converting GraphQL to Cypher, something like this library, but for RedisGraph. I came across graphql-compiler when going through this issue.

Btw, redisgraph-py now supports query parameters (Ref), so maybe this doc can be updated. But yeah, RedisGraph still doesn’t have complete Cypher coverage.

Also, we really appreciate the kensho guys contributing to this project and keeping it open source (and for also writing awesome blogs!). I’ll make sure to raise PRs if I find myself modifying the code for our use-case, or if I find any bugs 😃.

0reactions
obi1kenobicommented, Jan 7, 2021

Also, if I understood correctly, you mentioned that this issue is resolved in the v2.0 prereleases? If so, I’d like to mark it as closed since fixing the reported problem doesn’t require any further code changes, and simply requires v2.0 to be released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - TypeError: __init__() got an unexpected keyword ...
What action="store_true" means is that if the argument is given on the command line then a True value should be stored in the...
Read more >
init__() got an unexpected keyword argument 'max_iter'?
TypeError: init() got an unexpected keyword argument 'max_iter'. I m running the linear regression code in Community edition. Google says reinstall --.
Read more >
TypeError: __init__() got an unexpected keyword argument ...
The TypeError: init () got an unexpected keyword argument 'unbound_message' occurs when using an old version of Werkzeug with a more recent version...
Read more >
tensor.__init__() got an unexpected keyword argument 'shape'
TypeError : init() got an unexpected keyword argument 'sign' ... I also change the Parameter(shape, nonneg=True) instead of Parameter(shape, sign='positive'). but ...
Read more >
TypeError: __init__() got an unexpected keyword argument ...
After completing all the procedure, the following error was thrown while running run.py TypeError: init() got an unexpected keyword argument ...
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 Reddit Thread

No results found

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