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.

M2M connection is broken

See original GitHub issue

Hi,

I have following models:

class Place(models.Model):
    categories = models.ManyToManyField(PlaceCategory, related_name='places')
class PlaceCategory(models.Model):
    name = models.CharField(max_length=255, unique=True)

Furthermore, I have following DjangoObjectType models:

class PlaceNode(DjangoObjectType):
    class Meta:
        model = Place
        interfaces = (graphene.relay.Node, )
class PlaceCategoryNode(DjangoObjectType):
    class Meta:
        model = PlaceCategory
        interfaces = (graphene.relay.Node, )

Then when I execute this query:

{
  placeCategories {
    edges {
      node {
        id
        places {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}

everything works great but when I try to execute this one:

{
  places {
    edges {
      node {
        id
        categories {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}

I get errors:

Cannot combine queries on two different base models.

It seems that M2M connection is working improperly and it is unable to fetch related objects from instance where M2M is defined.

Has anyone run into the same problem ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
kozickikarolcommented, May 11, 2017

You can just define custom resolver and return queryset. It should work.

In my case it would be:

class PlaceNode(DjangoObjectType):
    class Meta:
        model = Place
        interfaces = (graphene.relay.Node, )

    categories = DjangoFilterConnectionField(PlaceCategoryNode)

    def resolve_categories(self, *args):
        return self.categories.all()

But this is only a workaround. In my case when I have lots of M2M it is annoying that I have to define custom resolvers for all of them.

2reactions
spockNinjacommented, Jul 5, 2017

@keremgocen No, this was not merged in time for the 1.3 release. There has not been a new release to pypi since this was merged. From the commit log, it looks like a release is pushed about every month or so, so I don’t expect it will be too long.

In the meantime, you can pull down master instead of 1.3.

pip uninstall graphene-django pip install git+https://github.com/graphql-python/graphene-django.git

or in requirements.txt pip install git+ssh://git@github.com/graphql-python/graphene-django.git#egg=graphene-django

Read more comments on GitHub >

github_iconTop Results From Across the Web

M2M (Machine To Machine) Is Broken: And How To Fix It?
Sounds great, right? Well, there are some pieces of this M2M vision that, currently broken, need to be fixed for M2M to work...
Read more >
SIM is not working - Global M2M SIM Support - Zendesk
If your SIM is connecting to the network OK but not making a data connection, check that the correct Access Point Name (APN)...
Read more >
The challenges of M2M massive access in wireless cellular ...
The basic idea is to offload the network by exploiting the physical proximity of the terminals, e.g., enabling direct communication between user devices,...
Read more >
M2M application characteristics and their implications ... - Ofcom
This purpose of this study was to assess the potential implications for radio spectrum of growing demand for machine to machine (M2M) ...
Read more >
Breaking a Lightweight M2M Authentication Protocol for ...
Generally, a smart sensor is a resource-constrained device which is responsible for gathering data from the monitored area. Machine-to-Machine (M2M) ...
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