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.

Unable to subclass or emulate DjangoObjectType

See original GitHub issue

Subclassing DjangoObjectType so as to customise it for use in derived objects in the schema causes the execution of:

assert is_valid_django_model(model)

which fails the assertion due toclass MyNewClass(DjangoObjectType): not having a meta class, as it meant to be a subclass of DjangoObjectType for reuse later on, not and thus does not have a Meta class of its own.

Its also not possible to emulate DjangoObjectType by copying DjangoObjectType, subclassing the new class from ObjectType, this gets past assert is_valid_django_model(model) but then things run into trouble in graphene_django.registry.Registry which runs:

assert issubclass(cls, DjangoObjectType), 'Only DjangoObjectTypes can be registered, received "{}"'.format(cls.__name__)

Which fails due to the explicit check for DjangoObjectType.

It shouldn’t require a fork of the entirety of graphene-django just to create a subclass of DjangoObjectType, either the Registry should be more flexible, or DjangoObjectType should be more flexible.

One option might be to use of Abstract Base Classes to enable a specific set of checks via https://docs.python.org/3/reference/datamodel.html?highlight=__subclass#class.__subclasscheck__

Another way would be to just drop these assertions and throw appropriate exceptions when we reach the situations they were designed to guard against. If we check that its a Django model to ensure that Meta exists, why not just throw a “Not A Django Model” exception when we try to do something later on that actually needs the Django model Meta information instead of asserting something way up the call stack that gets in the way of other things.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
techdragoncommented, Jun 12, 2019

I think this should probably stay open since it represents a rather significant limitation that deserves some kind of solution.

4reactions
metakotcommented, Apr 13, 2019

But who stops you from using

class Meta:
    abstract = True

in a subclass ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django/Graphene Mutation error "you need to pass a valid ...
This is the problem: class CreateProductCategory(DjangoObjectType). You need to inherit graphene.Mutation , not DjangoObjectType , for ...
Read more >
Queries & ObjectTypes - Graphene-Python
Then all query-able related models must be defined as DjangoObjectType subclass, or they will fail to show if you are trying to query...
Read more >
Prerequisite to build inference - inference - GitAnswer
1 Answer: I think there is nothing special you'd need to do for RISCV64 assuming you have the compiler toolchain. You could just...
Read more >
[FIXED] Graphene/Django mutations return null ~ PythonFixing
define schema class PostType(DjangoObjectType): class Meta: model = Post fields = ('title', 'body', 'author', 'published_date', 'status', ...
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