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.

BaseDjangoFormMutation should use from_global_id when fetching existing instance

See original GitHub issue

We are using DjangoFormMutations (#217), and what I’m not sure about is how Django’s ID/PKs are resolved in the process. They still appear in base64 encoding in the GraphQL output but in BaseDjangoFormMutation method they are processed as is.

The error returned from GraphQL shows that the instance is fetched using the string with the base64 encoded ID instead of the decoded PK integer value.

"errors": [
  {
    "message": "invalid literal for int() with base 10: 'UHJvamVjdE5vZGU6MTA1'",

I think the following code from /graphene_django/forms/mutation.py should use from_global_id instead of the value as is:

@classmethod
def get_form_kwargs(cls, root, info, **input):
    kwargs = {'data': input}

    pk = input.pop('id', None)
    if pk:
        instance = cls._meta.model._default_manager.get(pk=pk)
        kwargs['instance'] = instance

    return kwargs

I’m not 100% sure about this. We are using UUIDs next to Django’s IDs so I had to extend get_form_kwargs anyway, and it works fine that way. But it’s not working for ID. If the above is the correct location for the fix I can create a pull request. Just wanted to check back if I’m understanding this correctly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

6reactions
stale[bot]commented, Jun 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

3reactions
citadelgradcommented, Jan 31, 2019

IMO this issue should be closed and the documentation updated to explain how these hashed IDs are being created.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BaseDjangoFormMutation should use from_global_id when ...
BaseDjangoFormMutation should use from_global_id when fetching existing instance ... We are using DjangoFormMutations (#217), and what I'm not ...
Read more >
Custom Nodes - Graphene-Python
Any object that inherits from it has to implement a get_node method for retrieving a Node by an id. Quick example¶. Example usage...
Read more >
How to get instance from global id in Django with Graphene ...
graphql_relay has a function from_global_id which returns the model_name and the instance_id . However, it seems that to retrieve the model ...
Read more >
Relay/GraphQL: De-mystifying Node Interface/ID | Code Oil
The Relay/GraphQL tutorial's chapter on Object Identification elucidates how Relay/GraphQL requires Node IDs for re-fetching objects.
Read more >
Relay Support - Join Monster - Read the Docs
The Node Interface allows Relay to fetch an instance of any type. This could technically be useful without using Relay on the client....
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