Graphene-django: cookbook example doesn't work?

Created on 28 Sep 2016  路  7Comments  路  Source: graphql-python/graphene-django

I am trying to run cookbook example and when I try to get item by ID, web client raises an error:

query {
ingredient(id: "SW5ncmVkaWVudE5vZGU6MQ==") { # actual id is takef rom the previous request
name
}
}
screen shot 2016-09-28 at 11 49 07

Most helpful comment

@zamesilyasa were you able find a solution for this? running into same issue here.

All 7 comments

I followed the docs on Cookbook as well and it seems that those are not updated for the newest django-filter updates. Any idea what would be changing for the new filtering release?

Thanks!

I also followed the docs to build the cookbook example.

An error occurred, so I checked the issues and ended here. After that I tried @jtaylor32's graphene-tutorial repository that looks very similar to my code. The same error occurs.

# $ git clone https://github.com/jtaylor32/graphene-tutorial                                                                                                                           Cloning into 'graphene-tutorial'...
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 22 (delta 0), reused 22 (delta 0), pack-reused 0
Unpacking objects: 100% (22/22), done.

# $ cd graphene-tutorial

# $ mkvirtualenv -a . graphene-tutorial
Setting project for graphene-tutorial to /Users/rm/used_repos/graphene-tutorial
pyenv-virtualenv: deactivate must be sourced. Run 'source deactivate' instead of 'deactivate'

# $ pip install -r requirements.txt
Collecting Django==1.10.2 (from -r requirements.txt (line 1))
  Using cached Django-1.10.2-py2.py3-none-any.whl
Collecting django-filter==0.15.2 (from -r requirements.txt (line 2))
  Using cached django_filter-0.15.2-py2.py3-none-any.whl
Collecting graphene==1.0.2 (from -r requirements.txt (line 3))
  Using cached graphene-1.0.2.tar.gz
Collecting graphene-django==1.0 (from -r requirements.txt (line 4))
  Using cached graphene-django-1.0.tar.gz
Collecting graphql-core==1.0 (from -r requirements.txt (line 5))
  Using cached graphql-core-1.0.tar.gz
Collecting graphql-relay==0.4.4 (from -r requirements.txt (line 6))
  Using cached graphql-relay-0.4.4.tar.gz
Collecting iso8601==0.1.11 (from -r requirements.txt (line 7))
  Using cached iso8601-0.1.11-py2.py3-none-any.whl
Collecting promise==0.4.2 (from -r requirements.txt (line 8))
  Using cached promise-0.4.2.tar.gz
Collecting singledispatch==3.4.0.3 (from -r requirements.txt (line 9))
  Using cached singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting six==1.10.0 (from -r requirements.txt (line 10))
  Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: Django, django-filter, six, promise, graphql-core, graphql-relay, graphene, iso8601, singledispatch, graphene-django
  Running setup.py install for promise ... done
  Running setup.py install for graphql-core ... done
  Running setup.py install for graphql-relay ... done
  Running setup.py install for graphene ... done
  Running setup.py install for graphene-django ... done
Successfully installed Django-1.10.2 django-filter-0.15.2 graphene-1.0.2 graphene-django-1.0 graphql-core-1.0 graphql-relay-0.4.4 iso8601-0.1.11 promise-0.4.2 singledispatch-3.4.0.3 six-1.10.0
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# $ python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/management/base.py", line 342, in execute
    self.check()
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks
    issues.extend(super(Command, self)._run_checks(**kwargs))
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/management/base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/urls/resolvers.py", line 313, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
    return import_module(self.urlconf_name)
  File "/Users/rm/.pyenv/versions/3.5.2/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/rm/used_repos/graphene-tutorial/cookbook/urls.py", line 21, in <module>
    from cookbook.schema import schema
  File "/Users/rm/used_repos/graphene-tutorial/cookbook/schema.py", line 3, in <module>
    import cookbook.ingredients.schema
  File "/Users/rm/used_repos/graphene-tutorial/cookbook/ingredients/schema.py", line 36, in <module>
    class Query(AbstractType):
  File "/Users/rm/used_repos/graphene-tutorial/cookbook/ingredients/schema.py", line 41, in Query
    all_ingredients = DjangoFilterConnectionField(IngredientNode)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/graphene_django/filter/fields.py", line 20, in __init__
    self.filterset_class = get_filterset_class(filterset_class, **meta)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/graphene_django/filter/utils.py", line 32, in get_filterset_class
    return custom_filterset_factory(**meta)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/graphene_django/filter/filterset.py", line 127, in custom_filterset_factory
    'Meta': meta_class
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/graphene_django/filter/filterset.py", line 55, in __new__
    new_class = super(GrapheneFilterSetMetaclass, cls).__new__(cls, name, bases, attrs)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django_filters/filterset.py", line 224, in __new__
    filters[order_by_field] = new_class.get_ordering_filter(opts, filters)
  File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django_filters/filterset.py", line 375, in get_ordering_filter
    "'order_by' is not compatible with the 'fields' dict syntax. Use OrderingFilter instead."
AssertionError: 'order_by' is not compatible with the 'fields' dict syntax. Use OrderingFilter instead.

The last lines of the traceback File "/Users/rm/.virtualenvs/graphene-tutorial/lib/python3.5/site-packages/django_filters/filterset.py", line 375, in get_ordering_filter "'order_by' is not compatible with the 'fields' dict syntax. Use OrderingFilter instead." AssertionError: 'order_by' is not compatible with the 'fields' dict syntax. Use OrderingFilter instead.. led me to django-filter.

django-filter==0.15.0 made a lot of related changes to OrderingFilter.

There is also a migration guide.

I hope the provided information helps to find out the problem.

if you're only using this for trying out and not for production, you can comment out django-filters assertion check on site-packages/django_filters/filterset.py line 374-375:

@classmethod def get_ordering_filter(cls, opts, filters): # assert not isinstance(opts.fields, dict), \ # "'order_by' is not compatible with the 'fields' dict syntax. Use OrderingFilter instead."

that will resolve the assertionerror issue and graphql cookbook will work fine

@zamesilyasa were you able find a solution for this? running into same issue here.

Not yet.

@zamesilyasa @nsuthar0914 I fixed it in PR #43. Briefly, graphene imports a lot of things to the root library so you can just do graphene.Blah and graphene.Foo. However, graphene.Field is not the same as graphene.Node.Field. I don't know what the difference is, I just (luckily) noticed this working through another example. After changing x = Field(XNode) to x = Node.Field(XNode) for category and ingredients I got the below screenshot. Cheers!

screenshot 2016-11-03 at 17 30 46

@chriscauley, hi can u show what are the files that u have changed from graphene.Field to graphene.Node.Field? Apparently, I don't see any graphene.Field anywhere in the example code for cookbook.

Was this page helpful?
0 / 5 - 0 ratings