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.

DjangoModelFormMutation receive uncoded ID

See original GitHub issue

Hi everyone As already we know, queries with relay interface gives ID fields as base64; but form based mutations receive ID as natural string. Can we change to receive ID’s as base64 like relay?

class Genre(models.Model):
  name = models.CharField(max_length=200)

  def __str__(self):
    return self.name

class GenreForm(forms.ModelForm):
  class Meta:
    model = Genre
    fields = ['name']

class GenreNode(DjangoObjectType):
  class Meta:
    model = Genre
    filter_fields = ['name']
    interfaces = (relay.Node, )

class Queries(ObjectType):
  genres = DjangoFilterConnectionField(GenreNode)
  genre = relay.Node.Field(GenreNode)

class GenreMutation(DjangoModelFormMutation):
  genre = Field(GenreNode)

  class Meta:
    form_class = GenreForm

class Mutations():
  genre_mutation = GenreMutation.Field()

When you send the id as a relay id, you got this error: "invalid literal for int() with base 10: 'Q2F0ZWdvcnlOb2RlOjEy'"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jkimbocommented, Mar 18, 2020

Regarding the issue @javialon26 - in your example you’ve created a plain DjangoModelFormMutation which doesn’t know anything about relay. Adding a custom field to your GenreForm class to parse the ID as a relay ID would probably solve your issue.

1reaction
jkimbocommented, Mar 18, 2020

@ulgens the stalebot is useful to clean up old issues where the issue is no longer relevant but it can be overzealous and I haven’t been very good at keeping on top of issues. I’ll bump the days it takes to mark an issue as stale (to 120) and I’ll try and keep on top of issues as best I can. Any help with that would be most appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations - Graphene-Python
MyMutation will automatically receive an input argument. This argument should be a dict where the key is name and the value is a...
Read more >
why flask graphene return wrong id? - Stack Overflow
when i print the id before returning, the code print the right value ( same with id in mongo ). but the client...
Read more >
GraphQL + Django: DjangoModelFormMutation Walkthrough
AssertionError at /graphql You need to pass a valid Django Model in Query.Meta, received "None". I'm not entirely sure what causes this error, ......
Read more >
How to use the graphene.ID function in graphene - Snyk
To help you get started, we've selected a few graphene.ID examples, based on popular ways it is used in public projects.
Read more >
How to get Django Graphene ModelForm Mutation to apply
ID (required=True) class Meta: model = SubjectMark class AddSubjectMarkMutation(DjangoModelFormMutation): subject_mark = graphene.
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